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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user