How we can open multiple files(images) in Qt. I have written a code but this only opens a single image. Here is the Qt code.
dialog.setNameFilter(tr("Images (*.png *.xpm *.jpg)"));
tr("Open Images"), "C:/Users/hamza/Desktop/New folder", tr("Image Files (*.png *.jpg *.bmp);;All Files (*.*)"));
if (dialog.exec())
fileName=dialog.selectedFiles();
if (!fileName.isEmpty())
{
image = image.scaledToWidth(ui->label_pic->width(),Qt::SmoothTransformation);
ui
->label_pic
->setPixmap
(QPixmap::fromImage(image
));
}
QFileDialog dialog(this);
dialog.setNameFilter(tr("Images (*.png *.xpm *.jpg)"));
dialog.setViewMode(QFileDialog::Detail);
dialog.setFileMode(QFileDialog::ExistingFiles);
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Images"), "C:/Users/hamza/Desktop/New folder", tr("Image Files (*.png *.jpg *.bmp);;All Files (*.*)"));
if (dialog.exec())
fileName=dialog.selectedFiles();
if (!fileName.isEmpty())
{
QImage image(fileName);
image = image.scaledToWidth(ui->label_pic->width(),Qt::SmoothTransformation);
ui->label_pic->setPixmap(QPixmap::fromImage(image));
}
To copy to clipboard, switch view to plain text mode
Bookmarks