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

Doing style->drawControl(QStyle::CE_ProgressBar) inside QStyledItemDelegate causes a crash

    XMLWordPrintable

Details

    • Windows
    • 8f283aa29 (dev), 3eb0c8007 (6.7.1), 35afe09b0 (6.7)

    Description

      Regression from 6.6.2. Here's the code:

      #include <QApplication>
      #include <QMainWindow>
      #include <QStyledItemDelegate>
      #include <QListWidget>
      
      class Delegate : public QStyledItemDelegate {
      public:
          using QStyledItemDelegate::QStyledItemDelegate;
      
          void paint(QPainter * p, const QStyleOptionViewItem & option, const QModelIndex & index) const override {        
              QStyleOptionProgressBar optProgress;
              optProgress.rect = option.rect;
              optProgress.minimum = 0;
              optProgress.maximum = 100;
              optProgress.progress = 50;
              optProgress.textVisible = false;
              if (auto* style = option.widget->style(); style != nullptr)
                  style->drawControl(QStyle::CE_ProgressBar, &optProgress, p, option.widget);
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QMainWindow w;
      
          auto* view = new QListWidget{&w};
          view->setItemDelegate(new Delegate{view});
          w.setCentralWidget(view);
          view->addItem("abc");
      
          w.show();
          return a.exec();
      } 

      Result in 6.6.2: progress bar displayed.

      Result in 6.7.0: crash (access violation somewhere inside Qt).

      Attachments

        For Gerrit Dashboard: QTBUG-124447
        # Subject Branch Project Status CR V

        Activity

          People

            santhoshkumar Santhosh Kumar Selvaraj
            alexium Alex
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes