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
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
imagegallery.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
mainwindow.cpp
|
mainwindow.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
imagegallery.h \
|
||||||
mainwindow.h
|
mainwindow.h
|
||||||
|
|
||||||
FORMS += \
|
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 <QApplication>
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication app(argc, argv);
|
||||||
MainWindow w;
|
MainWindow mainWindow;
|
||||||
w.show();
|
|
||||||
return a.exec();
|
mainWindow.show();
|
||||||
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(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()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
|
||||||
}
|
}
|
||||||
|
|||||||
13
mainwindow.h
13
mainwindow.h
@@ -1,13 +1,5 @@
|
|||||||
#ifndef MAINWINDOW_H
|
|
||||||
#define MAINWINDOW_H
|
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include "imagegallery.h"
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
namespace Ui {
|
|
||||||
class MainWindow;
|
|
||||||
}
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
@@ -18,6 +10,5 @@ public:
|
|||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
ImageGallery *imageGallery;
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
|
||||||
|
|||||||
Reference in New Issue
Block a user