From c7e8133a95220e0ce96171024e34de8c53975b9c Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 10 Nov 2021 15:04:08 +0100 Subject: [PATCH] QSlider: Always set the sunken state and the active control MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit initStyleOption should initialize the state based on which controls are pressed or hovered, not only when painting but also when calling other style APIs. Pick-to: 6.2 Task-number: QTBUG-98093 Change-Id: I482793b7de38657aa36a20d0abab8845155ad0e9 Reviewed-by: Jan Arve Sæther --- src/widgets/widgets/qslider.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/widgets/widgets/qslider.cpp b/src/widgets/widgets/qslider.cpp index d2eeec494a..22a6d323fe 100644 --- a/src/widgets/widgets/qslider.cpp +++ b/src/widgets/widgets/qslider.cpp @@ -155,6 +155,13 @@ void QSlider::initStyleOption(QStyleOptionSlider *option) const option->pageStep = d->pageStep; if (d->orientation == Qt::Horizontal) option->state |= QStyle::State_Horizontal; + + if (d->pressedControl) { + option->activeSubControls = d->pressedControl; + option->state |= QStyle::State_Sunken; + } else { + option->activeSubControls = d->hoverControl; + } } bool QSliderPrivate::updateHoverControl(const QPoint &pos) @@ -317,12 +324,6 @@ void QSlider::paintEvent(QPaintEvent *) opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; if (d->tickPosition != NoTicks) opt.subControls |= QStyle::SC_SliderTickmarks; - if (d->pressedControl) { - opt.activeSubControls = d->pressedControl; - opt.state |= QStyle::State_Sunken; - } else { - opt.activeSubControls = d->hoverControl; - } style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, this); }