import directory
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "imagegallery.h"
|
||||
#include <QPixmap>
|
||||
#include <QImageReader>
|
||||
|
||||
ImageGallery::ImageGallery(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
@@ -25,3 +26,21 @@ void ImageGallery::addImage(const QString &imagePath)
|
||||
scrollLayout->addWidget(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 <QLabel>
|
||||
#include <QList>
|
||||
#include <QDir>
|
||||
|
||||
class ImageGallery : public QWidget
|
||||
{
|
||||
@@ -14,6 +15,7 @@ class ImageGallery : public QWidget
|
||||
public:
|
||||
explicit ImageGallery(QWidget *parent = nullptr);
|
||||
void addImage(const QString &imagePath);
|
||||
void addImagesFromDirectory(const QString &directoryPath);
|
||||
|
||||
private:
|
||||
QScrollArea *scrollArea;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
imageGallery = new ImageGallery(this);
|
||||
setCentralWidget(imageGallery);
|
||||
setWindowTitle("Image Gallery");
|
||||
imageGallery->addImage("/home/krzys/Obrazy/kod.png");
|
||||
imageGallery->addImage("/home/krzys/Obrazy/kod.png");
|
||||
setWindowTitle("Kallery Image Gallery");
|
||||
imageGallery->addImagesFromDirectory("/home/krzys/Obrazy");
|
||||
resize(800, 600);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user