first version

This commit is contained in:
2025-02-19 15:23:20 +01:00
parent acca5fb630
commit c4d2e44836
10 changed files with 70 additions and 22 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build/

View File

@@ -9,10 +9,12 @@ CONFIG += c++17
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
imagegallery.cpp \
main.cpp \
mainwindow.cpp
HEADERS += \
imagegallery.h \
mainwindow.h
FORMS += \

File diff suppressed because one or more lines are too long

27
imagegallery.cpp Normal file
View File

@@ -0,0 +1,27 @@
#include "imagegallery.h"
#include <QPixmap>
ImageGallery::ImageGallery(QWidget *parent) : QWidget(parent)
{
scrollArea = new QScrollArea(this);
scrollWidget = new QWidget(scrollArea);
scrollLayout = new QVBoxLayout(scrollWidget);
scrollArea->setWidgetResizable(true);
scrollArea->setWidget(scrollWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(scrollArea);
setLayout(mainLayout);
}
void ImageGallery::addImage(const QString &imagePath)
{
QLabel *imageLabel = new QLabel(scrollWidget);
QPixmap pixmap(imagePath);
imageLabel->setPixmap(pixmap.scaledToWidth(400, Qt::SmoothTransformation));
imageLabel->setAlignment(Qt::AlignCenter);
scrollLayout->addWidget(imageLabel);
imageLabels.append(imageLabel);
}

25
imagegallery.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef IMAGEGALLERY_H
#define IMAGEGALLERY_H
#include <QWidget>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QLabel>
#include <QList>
class ImageGallery : public QWidget
{
Q_OBJECT
public:
explicit ImageGallery(QWidget *parent = nullptr);
void addImage(const QString &imagePath);
private:
QScrollArea *scrollArea;
QWidget *scrollWidget;
QVBoxLayout *scrollLayout;
QList<QLabel*> imageLabels;
};
#endif // IMAGEGALLERY_H

View File

@@ -1,11 +1,11 @@
#include "mainwindow.h"
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.show();
return app.exec();
}

View File

@@ -1,14 +1,16 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
imageGallery = new ImageGallery(this);
setCentralWidget(imageGallery);
setWindowTitle("Image Gallery");
imageGallery->addImage("/home/krzys/Obrazy/kod.png");
imageGallery->addImage("/home/krzys/Obrazy/kod.png");
resize(800, 600);
}
MainWindow::~MainWindow()
{
delete ui;
}

View File

@@ -1,13 +1,5 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
#include "imagegallery.h"
class MainWindow : public QMainWindow
{
@@ -18,6 +10,5 @@ public:
~MainWindow();
private:
Ui::MainWindow *ui;
ImageGallery *imageGallery;
};
#endif // MAINWINDOW_H