import directory
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "imagegallery.h"
|
#include "imagegallery.h"
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QImageReader>
|
||||||
|
|
||||||
ImageGallery::ImageGallery(QWidget *parent) : QWidget(parent)
|
ImageGallery::ImageGallery(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
@@ -25,3 +26,21 @@ void ImageGallery::addImage(const QString &imagePath)
|
|||||||
scrollLayout->addWidget(imageLabel);
|
scrollLayout->addWidget(imageLabel);
|
||||||
imageLabels.append(imageLabel);
|
imageLabels.append(imageLabel);
|
||||||
}
|
}
|
||||||
|
void ImageGallery::addImagesFromDirectory(const QString &directoryPath){
|
||||||
|
QDir directory(directoryPath);
|
||||||
|
QStringList filters;
|
||||||
|
const QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
|
||||||
|
|
||||||
|
for(const QByteArray &format : supportedFormats){
|
||||||
|
filters.append("*." + QString(format).toLower());
|
||||||
|
}
|
||||||
|
|
||||||
|
directory.setNameFilters(filters);
|
||||||
|
directory.setFilter(QDir::Files | QDir::Readable);
|
||||||
|
directory.setSorting(QDir::Name);
|
||||||
|
|
||||||
|
const QFileInfoList fileList = directory.entryInfoList();
|
||||||
|
for(const QFileInfo &fileInfo : fileList) {
|
||||||
|
addImage(fileInfo.absoluteFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
class ImageGallery : public QWidget
|
class ImageGallery : public QWidget
|
||||||
{
|
{
|
||||||
@@ -14,6 +15,7 @@ class ImageGallery : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit ImageGallery(QWidget *parent = nullptr);
|
explicit ImageGallery(QWidget *parent = nullptr);
|
||||||
void addImage(const QString &imagePath);
|
void addImage(const QString &imagePath);
|
||||||
|
void addImagesFromDirectory(const QString &directoryPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScrollArea *scrollArea;
|
QScrollArea *scrollArea;
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include <QApplication>
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
{
|
{
|
||||||
imageGallery = new ImageGallery(this);
|
imageGallery = new ImageGallery(this);
|
||||||
setCentralWidget(imageGallery);
|
setCentralWidget(imageGallery);
|
||||||
setWindowTitle("Image Gallery");
|
setWindowTitle("Kallery Image Gallery");
|
||||||
imageGallery->addImage("/home/krzys/Obrazy/kod.png");
|
imageGallery->addImagesFromDirectory("/home/krzys/Obrazy");
|
||||||
imageGallery->addImage("/home/krzys/Obrazy/kod.png");
|
|
||||||
resize(800, 600);
|
resize(800, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user