0

I am trying to build an application where I will select a directory (using qtreeview model based widget) and upon the selection of a folder, its containing image files will be shown in a qlistview model based widget (& later perform tasks after selection of the certain image). I have succeeded upto showing the image files as icons in the qlistview (model based) but I need to show the images in their respective thumbnails, not icons on the listView.

Can anyone please help me? I have checked out - http://doc.qt.io/qt-5/qlistview.html: Here only icons can be implemented (ViewMode as IconMode), not thumbnails.

Inside the constructor-

QString sPath = "F:/";
dirModel = new QFileSystemModel (this);                     // setting up 
the directory model on tree view
dirModel -> setRootPath(sPath);
ui->treeView->setModel(dirModel);

fileModel = new QFileSystemModel (this);                    // setting up 
the file model on list view
fileModel ->setFilter(QDir::NoDotAndDotDot | QDir::Files);
fileModel -> setRootPath(sPath);

QStringList filters;            // list view filters to show only image 
files
filters << "*.JPG" << "*.PNG" << "*.ico";
fileModel->setNameFilters(filters);
fileModel -> setNameFilterDisables(false);
ui->listView->setModel(fileModel);

On the event functions-

void MainWindow::on_treeView_clicked(const QModelIndex &index)
{
QString sPath = dirModel->fileInfo(index).absoluteFilePath();

ui->listView->setRootIndex(fileModel->setRootPath(sPath));

folderPath = sPath;
}

void MainWindow::on_listView_clicked(const QModelIndex &index)
{
if(!folderPath.isEmpty())
    {
    QString filename = fileModel->fileInfo(index).absoluteFilePath();;
    QPixmap pix(filename);

    int w = ui->imgLabel->width ();
    int h = ui->imgLabel->height ();
    ui->imgLabel->setPixmap (pix.scaled (w,h,Qt::KeepAspectRatio));
}
}

Screenshot- no_thumbnail.

Protik
  • 53
  • 1
  • 9

0 Answers0