Qt load large number image and display it efficiently.



  • I need to display large number of images in a Window like in a grid, and the image count can be more that 10000. Currently I have created a tableView and displaying image in each cell. But this creating problem when the image number is very large and the application uses considerable amount of RAM.

    I found in QML ImageView there is an option for cache and the image is loading when only scroll to that area. But my project is widget based. So is there anything exist on Qt widget based applications. Like load and display images only when we scroll to that area.


  • Lifetime Qt Champion

    Hi,

    What are you using to do the displaying of the image ?

    In any case, you might be interested by QPixmapCache



  • Are you using full resolution or just thumbnails?



  • I need to display, 128x128 pixel size, in a table grid.

    This is the relevant part of the code,

    int totalColumn = 15;
    int cellWidth = 128;
    int cellHeight = 128;
    for(int i=0;i<ImagePathList.size();i++){
            QString imagePath =  imageDir+"/"+ImagePathList.at(i);
            QPixmap pix(imagePath);
            if(!pix.isNull()){
              pix= pix.scaled(cellWidth,cellHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
              QStandardItem *item = new QStandardItem();
              item->setData(QVariant(pix), Qt::DecorationRole);
              model->setItem(row, col, item);
    
              col++;
              if(col==totalColumn){
                  col=0;
                  row++;
              }
    
            }
        }
    

  • Lifetime Qt Champion

    You should write you own model and pixmap cache.

    Doing it like you are currently, you are both blocking your application and using an insane amount of RAM depending on the number of pictures.



  • @SGaist

    Thank for the answer, right now I executing the above code from a thread, so no issue like GUI blocking. But as you pointed out the RAM usage getting higher for large number of image, there I may need to proceed with the solution you suggested. Do you have any reference regarding write my our model and pixmap cache.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.