Important: Please read the Qt Code of Conduct -

Show Images with Pixmap: Memory

  • Hello,
    I want to display a large number of images with large size (each >100 MB).
    They should be displayed as a small preview picture with low resolution.
    Is it possible to avoid that they are all loaded into memory?

    What could be the proper way of doing it?

    Thanks for help.

  • Lifetime Qt Champion

    @TauCeti said in Show Images with Pixmap: Memory:

    What could be the proper way of doing it?

    Load them, create thumbnails and only store them in memory.

  • Still not sure how to solve this.

    QIcon thumbnail = QIcon(Pixmap::fromImage(image));
    QLabel *img = new QLabel(tab);
    img->scaledToWidth( .. );

    How do I create thumbnails? Just load them to a QIcon or QLabel with
    different size?

  • Moderators

    for example this creates a QVector filled with scaled (100 x 100) QPixmaps of a given folder

    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        QVector<QPixmap> myThumbNails;
        QDir dir(pathToImages);
        const QStringList entries = dir.entryList(QDir::Files);
        const QString path = pathToImages + QString("/%1");
        for(const QString &image : entries){
            QPixmap imgOrginal(path.arg(image) );
        return a.exec();

Log in to reply