first version
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
build/
|
||||
@@ -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 += \
|
||||
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
27
imagegallery.cpp
Normal file
27
imagegallery.cpp
Normal 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
25
imagegallery.h
Normal 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
|
||||
12
main.cpp
12
main.cpp
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
13
mainwindow.h
13
mainwindow.h
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user