Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1888

Slow QTreeWidgetItem.setForeground and QTreeWidgetItem.setBackground

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 6.2.3
    • PySide
    • None
    • CPython 3.10 x64
      PySide 6.2.3
      Windows 10 x64
    • Windows

    Description

      I'm developing an application that does data acquisition and plotting, with a target refresh rate of 60FPS.

      I use a QTreeWidget with 4 columns to hold the signals information. Depending on each signal's current value, the associated QTreeWidgetItem needs to update the font color and background. This update is done only if the QTreeWidgetItem is visible.

      There is a clear freeze when the updates occur (32 visible signals in the GIF), and I've determined that the freeze is caused by this code:

          if new_background_color is None:
              if self._background_color != self.background(0).color():
                  self.setBackground(0, self._background_color)
                  self.setBackground(1, self._background_color)
                  self.setBackground(2, self._background_color)
                  self.setBackground(3, self._background_color)
          else:
              if new_background_color != self.background(0).color():
                  self.setBackground(0, new_background_color)
                  self.setBackground(1, new_background_color)
                  self.setBackground(2, new_background_color)
                  self.setBackground(3, new_background_color)
      
          if new_font_color is None:
              if self.signal.color != self.foreground(0).color():
                  self.setForeground(0, self.signal.color)
                  self.setForeground(1, self.signal.color)
                  self.setForeground(2, self.signal.color)
                  self.setForeground(3, self.signal.color)
          else:
              if new_font_color != self.foreground(0).color():
                  self.setForeground(0, new_font_color)
                  self.setForeground(1, new_font_color)
                  self.setForeground(2, new_font_color)
                  self.setForeground(3, new_font_color)
      

       

      If I comment out that snippet each update of the QTreeWidgetitem (setting the text in column 1) takes ~6us. When the code is enabled, each time the background or foreground is changed takes 1.6ms per item. With a small visible count of 32 items this caused a clear freeze in the GUI (see the attached GIFs).

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            danielhrisca Daniel Hrisca
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes