I need to handle the display of thumbnails of photos in a separate stream, otherwise the code is processed for a very long time. I have basically a class class MainWindow model and variable:
mainwindow.h
public: static QStandardItemModel * model = new QStandardItemModel; static QStandardItem *item_one; static int rowTableDisk = 0; I create a stream to add thumbnails like this:
threadsminiature.h
#ifndef THREADSMINIATURE_H #define THREADSMINIATURE_H #include <QThread> #include <QImageReader> #include <mainwindow.h> class ThreadsMiniature : public QThread { public: explicit ThreadsMiniature(QString threadName, QString Path); void run(); QString _Path; private: QString name; // Имя потока }; #endif // THREADSMINIATURE_H threadsminiature.cpp
#include "threadsminiature.h" ThreadsMiniature::ThreadsMiniature(QString threadName, QString Path) : name(threadName), _Path(Path) { } void ThreadsMiniature::run() { int icoWidth = 200; int icoHeight = 200; QImageReader imageReader(_Path); QSize size; int image_width; int image_height; if (imageReader.supportsOption(QImageIOHandler::Size)) { size = imageReader.size(); image_width = size.width(); image_height = size.height(); } double ratio = (double)image_width / (double)image_height; if (ratio >= 1) { image_width = icoWidth; image_height = image_width / ratio; } else { image_height = icoHeight; image_width = image_height * ratio; } imageReader.setScaledSize(QSize(image_width, image_height)); //QImage image = imageReader.read(); MainWindow::item_one = new QStandardItem(); MainWindow::item_one->setData(QVariant(QPixmap::fromImage(imageReader.read())), Qt::DecorationRole); MainWindow::model->setItem(MainWindow::rowTableDisk, 2, MainWindow::item_one); } In the main code I fill in QTableView like this:
mainwindow.cpp
void MainWindow::TableListFiles(QStringList imagePathListCopy, QString DeviceFolder) { if (!DeviceFolder.isEmpty()) { //Заголовки столбцов QStringList horizontalHeader; horizontalHeader.append("Отметь, что перенести"); horizontalHeader.append("Кликабельные ссылки на изображения"); horizontalHeader.append("Папка в которую будет скопирован файл"); model->setHorizontalHeaderLabels(horizontalHeader); for(int i=0; i<imagePathListCopy.count(); i++) { if(rowTableDisk == 0) { item_one = new QStandardItem("Выбрать/Убрать всё"); model->setItem(rowTableDisk, 1, item_one); rowTableDisk++; //item_one = new QStandardItem("<a href=\""+imagePathListCopy.at(i)+"\">"+QFileInfo(imagePathListCopy.at(i)).fileName()+"</a>"); item_one = new QStandardItem(imagePathListCopy.at(i)); model->setItem(rowTableDisk, 1, item_one); QImage image(imagePathListCopy.at(i)); item_one = new QStandardItem(); item_one->setData(QVariant(QPixmap::fromImage(image)), Qt::DecorationRole); model->setItem(rowTableDisk, 2, item_one); item_one = new QStandardItem(DeviceFolder); model->setItem(rowTableDisk, 3, item_one); } else { //item_one = new QStandardItem("<a href=\""+imagePathListCopy.at(i)+"\">"+QFileInfo(imagePathListCopy.at(i)).fileName()+"</a>"); item_one = new QStandardItem(imagePathListCopy.at(i)); model->setItem(rowTableDisk, 1, item_one); ThreadsMiniature *threadB = new ThreadsMiniature(QString("thread_%1").arg(i),imagePathListCopy.at(i)); threadB->start(); //QImage image(imagePathListCopy.at(i)); item_one = new QStandardItem(DeviceFolder); model->setItem(rowTableDisk, 3, item_one); } rowTableDisk++; } } else { //Заголовки столбцов QStringList horizontalHeader; horizontalHeader.append("Отметь, что перенести"); horizontalHeader.append("Кликабельные ссылки на изображения"); model->setHorizontalHeaderLabels(horizontalHeader); int rowTableDisk = 0; for(int i=0;i<imagePathListCopy.count();i++) { if(rowTableDisk == 0) { item_one = new QStandardItem("Выбрать/Убрать всё"); model->setItem(rowTableDisk, 1, item_one); rowTableDisk++; //item_one = new QStandardItem("<a href=\""+imagePathListCopy.at(i)+"\">"+QFileInfo(imagePathListCopy.at(i)).fileName()+"</a>"); item_one = new QStandardItem(imagePathListCopy.at(i)); model->setItem(rowTableDisk, 1, item_one); } else { //item_one = new QStandardItem("<a href=\""+imagePathListCopy.at(i)+"\">"+QFileInfo(imagePathListCopy.at(i)).fileName()+"</a>"); item_one = new QStandardItem(imagePathListCopy.at(i)); model->setItem(rowTableDisk, 1, item_one); } rowTableDisk++; } } CheckBoxDelegate *CheckBoxD = new CheckBoxDelegate(this); HrefDelegate *HrefD = new HrefDelegate(this); TableDisk->setModel(model); TableDisk->setItemDelegateForColumn(0, CheckBoxD); TableDisk->setItemDelegateForColumn(1, HrefD); TableDisk->setColumnWidth(0,150); TableDisk->setColumnWidth(1,600); TableDisk->setColumnWidth(2,300); } How to use static QStandardItemModel * model = new QStandardItemModel; and static int rowTableDisk = 0; ?



modelandrowTableDiskconstant. This is a free translation of what the compiler tells you. - vegorov