我是QT的新手,我想要显示很多图像,并且能够从文件夹中加载它们,我只有一个图像的代码,它工作正常,但希望对许多图像具有相同的结果,这是我的代码:
QString imagePath = QFileDialog::getOpenFileName(
this,
tr("Open File"),
"",
tr("JPEG (*.jpg *.jpeg);;PNG (*.png);; BMP (*.bmp)" )
);
imageObject = new QImage();
imageObject->load(imagePath);
image = QPixmap::fromImage(*imageObject);
scene = new QGraphicsScene(this);
scene->addPixmap(image);
scene->setSceneRect(image.rect());
ui->graphicsView->setScene(scene);
答案 0 :(得分:1)
你可以使用open文件夹,这里只是snipsets:
const QString folderPath = QFileDialog::getExistingDirectory(this, tr("Image folder"));
if(!folderPath.isEmpty())
{
QDir dir(folderPath);
QStringList filter;
filter << QLatin1String("*.png");
filter << QLatin1String("*.jpeg");
filter << QLatin1String("*.jpg");
dir.setNameFilters(filter);
QFileInfoList filelistinfo = dir.entryInfoList();
QStringList fileList;
foreach (const QFileInfo &fileinfo, filelistinfo) {
QString imageFile = fileinfo.absoluteFilePath();
//imageFile is the image path, just put your load image code here
}
}