Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-97953

Custom QItemDelegate does not work properly with Qt 6.2.1

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Duplicate
    • Affects Version/s: 6.2.1
    • Fix Version/s: None
    • Component/s: Widgets: Itemviews
    • Labels:
      None
    • Platform/s:
      macOS

      Description

      Custom QItemDelegate (i.e. shown in table or list view rows) do not correctly paint in macOS but work fine on other platforms. Painting works as expected with Qt 5.15

      The following code demonstrates the problem (copied from https://forum.qt.io/topic/123889/problems-with-qsytyleditemdelegate-and-qstyleoptionprogressbar-on-macos):

      #include <QtWidgets>
      #include <QTimer>
      
      class Delegate final
        : public QStyledItemDelegate
      {
      public:
        explicit Delegate (QObject * parent = nullptr)
          : QStyledItemDelegate {parent}
        {
        }
      
        void paint (QPainter * painter, QStyleOptionViewItem const& option
                    , QModelIndex const& index) const
        {
          QStyleOptionProgressBar progress_bar_option;
          progress_bar_option.rect = option.rect;
          progress_bar_option.state = QStyle::State_Enabled;
          progress_bar_option.direction = QApplication::layoutDirection ();
          progress_bar_option.fontMetrics = QApplication::fontMetrics ();
          progress_bar_option.minimum = 0;
          progress_bar_option.maximum = 100;
          auto progress = index.data ().toLongLong ();
          auto percent = int (progress * 100 / index.data (Qt::UserRole).toLongLong ());
          progress_bar_option.progress = percent;
          progress_bar_option.text = QString::number (percent) + '%';
          progress_bar_option.textVisible = true;
          progress_bar_option.textAlignment = Qt::AlignCenter;
          QApplication::style ()->drawControl (QStyle::CE_ProgressBar, &progress_bar_option, painter);
        }
      };
      
      int main (int argc, char * argv[])
      {
        QApplication a {argc, argv};
        QListWidget w;
        Delegate d;
        w.setItemDelegate (&d);
        QListWidgetItem i1 {"Item 1"};
        i1.setData (Qt::UserRole, 100);
        w.addItem (&i1);
        QListWidgetItem i2 {"Item 2"};
        w.addItem (&i2);
        i2.setData (Qt::UserRole, 100);
        w.show ();
        QTimer t;
        qint64 n1 {0};
        qint64 n2 {0};
        t.callOnTimeout ([&] {
                           i1.setData (Qt::DisplayRole, (n1 += 2));
                           i2.setData (Qt::DisplayRole, (n2 += 10));
                          });
        t.start (1000);
        QObject::connect (&a, &QApplication::lastWindowClosed, &a, &QApplication::quit);
        return a.exec ();
      }
      

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              vhilshei Volker Hilsheimer
              Reporter:
              DanielSt Peter Staab
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes