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

QStyleSheetStyle::drawComplexControl draws groove when only Handle is asked for

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.8.3, 6.9.3
    • Widgets: Style Sheets
    • None
    • Windows 11

      In QStyleSheetStyle::drawComplexControl (src\qtbase\src\widgets\styles\qstylesheetstyle.cpp:3465) the code path for drawing the SC_SliderHandle sub-control of CC_Slider also draws the PseudoElement_SliderSubPage, and PseudoElement_SliderAddPage elements even when the groove sub-control is not requested.  Further, from inspection, it appears the SubPage and AddPage will not be drawn if only the groove sub-control is requested.

      Reproducing code.

      class QDrawComplexControlBug : public QSlider {
          using QSlider::QSlider;    void paintEvent(QPaintEvent* event) override
          {
              QStylePainter p(this);
              QStyleOptionSlider option;
              initStyleOption(&option);
              option.subControls = QStyle::SC_SliderHandle;
              p.drawComplexControl(QStyle::CC_Slider, option);
          }
      };
      
      int main(int argc, char* argv[])
      {
          auto app = QApplication(argc, argv);
          app.setStyleSheet("QSlider::handle {border:2px solid; border-radius : 5px; } QSlider::add-page {background: #223377; } QSlider::sub-page {background: #883366; }");    
          auto window = new QMainWindow();
          auto w = new QWidget();
          auto layout = new QVBoxLayout(w);
          w->setLayout(layout);
          auto slider = new QDrawComplexControlBug(Qt::Horizontal, w);
          slider->setRange(0, 100);
          slider->setValue(50);
          layout->addWidget(slider);
          window->setCentralWidget(w);
          window->show();    
          return app.exec();
      }
       

      If you remove the line app.setStyleSheet(...), then only the handle is rendered as expected.

       

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

            chehrlic Christian Ehrlicher
            tim-mitchell Tim Mitchell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes