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

Problem with drawing progressbar as QTreeView delegate again

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • None
    • 6.5.0
    • Widgets: Styles
    • None
    • All

    Description

      This is working:

      void ActiveItinerariesTableItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
      {
          if(index.column() == ActiveItinerariesTableModel::ColProgress) {
              QStyleOptionProgressBar opt;
              opt.initFrom(option.widget);
              opt.state |= QStyle::State_Horizontal;
              opt.maximum = 100;
              opt.progress = index.data().toInt();
              opt.rect = option.rect;
              opt.text = QString::number(opt.progress) + '%';
              opt.textVisible = true;
              opt.textAlignment = Qt::AlignCenter;
              option.widget->style()->drawControl(QStyle::CE_ProgressBar, &opt, painter);
              return;
          }
          Super::paint(painter, option, index);
      } 

      this is not:

      void ActiveItinerariesTableItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
      {
          if(index.column() == ActiveItinerariesTableModel::ColProgress) {
              QStyleOptionProgressBar opt;
              opt.initFrom(option.widget);
              //opt.state |= QStyle::State_Horizontal;
              opt.maximum = 100;
              opt.progress = index.data().toInt();
              opt.rect = option.rect;
              opt.text = QString::number(opt.progress) + '%';
              opt.textVisible = true;
              opt.textAlignment = Qt::AlignCenter;
              option.widget->style()->drawControl(QStyle::CE_ProgressBar, &opt, painter);
              return;
          }
          Super::paint(painter, option, index);
      } 

      Even if QStyleOptionProgressBar::QStyleOptionProgressBar() inits state correctly to have QStyle::State_Horizontal flag set, the QStyleOption::initFrom(QWidget*) function erases it. Since every QStyleOptionProgressBar instance must be initialized, setting of QStyle::State_Horizontal flag in ctor is futile.

      see also: https://bugreports.qt.io/browse/QTBUG-93412

      Attachments

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

        Activity

          People

            tpochep Timur Pocheptsov
            fanda Fanda Vacek
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes