Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListWidget slow with 25 QPixmap objects

QListWidget slow with 25 QPixmap objects

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 5.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Schiho
    wrote on last edited by
    #1

    Hi,

    I am generating a scrubbable Gallery with PyQt, for some reason, if my view has more than 25 QLabels, that hold QPixmap Images and some other QLabel Objects, my scrolling gets laggy. I think it has to do with the rendering of those 25 Images. When I remove the QtGui.QListView.IconMode the scrolling appears natural.

    alt text

    Any suggestions? I kinda have the feeling that in CPP QT this wasn't an issue.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      are you calling setItemWidget with a QLabel for every cell?!
      This is madness

      Use a custom QStyledItemDelegate. reimplement the paint event to paint the pixmap in the option.rect

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2
      • S Offline
        S Offline
        Schiho
        wrote on last edited by
        #3

        ashamed U got me, I am using setItemWidgets. I will have a look at your suggestion, meanwhile, if u have any sources of example that would be great. (and i like your gif)

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Sorry for the C++ but I don't know python:

          #include <QStyledItemDelegate>
          #include <QGuiApplication>
          #include <QPainter>
          
          class FullSizeIconDelegate : public QStyledItemDelegate{
              Q_OBJECT
              Q_DISABLE_COPY(FullSizeIconDelegate)
          public:
              explicit FullSizeIconDelegate(QObject* parent=Q_NULLPTR)
                  :QStyledItemDelegate(parent)
              {}
              virtual void QStyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE{
                  painter->drawPixmap(option.rect,index.data(Qt::DecorationRole).value<QPixmap>());
              }
          }
          

          then call tableWidget->setItemDelegate(new FullSizeIconDelegate(this)); and just set the images QPixmaps in the decoration role of the widget. For example: tableWidget->model()->setData(tableWidget->model()->index(0,0),QPixmap("myImage.png"),Qt::DecorationRole);

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          3
          • S Offline
            S Offline
            Schiho
            wrote on last edited by Schiho
            #5

            Ok, coming back to my problem, I've basically created a new QStyledItemDelegate and populated it with dummy data, but the speed didn't change at all.

            from PyQt4 import QtGui, QtCore
            from PyQt4.QtGui import QStyledItemDelegate, QPixmap
            from PyQt4.QtCore import Qt, QDir
            
            
            class ThumbnailDelegate(QtGui.QStyledItemDelegate):
                def __init__(self, parent = None):
                    QtGui.QStyledItemDelegate.__init__(self, parent)
            
            
                def paint(self, painter, option, index):
                    QStyledItemDelegate.paint(self, painter, option, index)
                    pixmap = QPixmap("../resources/images/assetBrowser.jpg")
                    painter.drawPixmap(option.rect, pixmap)
            
            

            and i am calling this as follows:

                        self.setItemDelegate(ThumbnailDelegate())
                        self.model().setData(self.model().index(0, 0), QPixmap("../resources/images/upArrow.png"), Qt.DecorationRole)
            

            So, before i was calling setItemWidget, now setItemDelegate... am i doing something wrong? And i still don't get why this would be faster than "setItemWidget"

            jsulmJ 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              You're loading a full size jpeg file on each paint event, that's not the most efficient. You should cache it or at least keep the image in memory.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • S Schiho

                Ok, coming back to my problem, I've basically created a new QStyledItemDelegate and populated it with dummy data, but the speed didn't change at all.

                from PyQt4 import QtGui, QtCore
                from PyQt4.QtGui import QStyledItemDelegate, QPixmap
                from PyQt4.QtCore import Qt, QDir
                
                
                class ThumbnailDelegate(QtGui.QStyledItemDelegate):
                    def __init__(self, parent = None):
                        QtGui.QStyledItemDelegate.__init__(self, parent)
                
                
                    def paint(self, painter, option, index):
                        QStyledItemDelegate.paint(self, painter, option, index)
                        pixmap = QPixmap("../resources/images/assetBrowser.jpg")
                        painter.drawPixmap(option.rect, pixmap)
                
                

                and i am calling this as follows:

                            self.setItemDelegate(ThumbnailDelegate())
                            self.model().setData(self.model().index(0, 0), QPixmap("../resources/images/upArrow.png"), Qt.DecorationRole)
                

                So, before i was calling setItemWidget, now setItemDelegate... am i doing something wrong? And i still don't get why this would be faster than "setItemWidget"

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Schiho To add to @SGaist : you could calculate thumbnail versions of the jpeg images and use these (you can store them in application data directory as cache).

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  Schiho
                  wrote on last edited by
                  #8

                  Hi guys, those are tiny pictures (200x160) and I am only loading (at most) 50 of them at once. I am more confused about the fact, that once it's loaded it is slow. I would kinda expect, that the loading process might take a little while, but after that the scrolling gets laggy.

                  @jsulm any ideas how to approach that, u aren't talking about pickles, are you?

                  Thanks

                  jsulmJ 1 Reply Last reply
                  0
                  • S Schiho

                    Hi guys, those are tiny pictures (200x160) and I am only loading (at most) 50 of them at once. I am more confused about the fact, that once it's loaded it is slow. I would kinda expect, that the loading process might take a little while, but after that the scrolling gets laggy.

                    @jsulm any ideas how to approach that, u aren't talking about pickles, are you?

                    Thanks

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Schiho Here is an older blog: http://blog.qt.io/blog/2009/01/26/creating-thumbnail-preview/
                    But you pictures are already small.
                    As @SGaist said you're reading image files on each paint event:

                    def paint(self, painter, option, index):
                            QStyledItemDelegate.paint(self, painter, option, index)
                            pixmap = QPixmap("../resources/images/assetBrowser.jpg") # Here you're reading from file
                            painter.drawPixmap(option.rect, pixmap)
                    

                    You should read them once and keep in memory.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    2

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved