diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-02-13 20:01:51 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-02-27 19:26:05 +0100 |
commit | f5105ea89a76d6051f058834d99385582cc61f85 (patch) | |
tree | ae65146d0d143fd88da582fa0064c66538f240ba /src/widgets/widgets/qscrollbar.cpp | |
parent | 519e3963fad0761bac5629b1f6eabc58060265c0 (diff) |
QStyleSheet: never treat styled scrollbars as transient
If a style sheet is applied to a scrollbar, then we cannot treat it as
transient, as the QStyleSheetStyle doesn't implement any fade-in/out
animation logic. And we also need to set the overlap to 0 (in both
the style sheet and the macOS style) if the scrollbars are not
transient; otherwise the opaque scrollbar will be placed on top of the
content.
Since a style sheet might only apply to a scrollbar based on its
orientation, we also have to pass the style option through to all calls
of the styleHint function.
And since that function is also called from other QStyle implementations
in the macOS style, we have to make sure that we call styleHint() on the
widget's style to get the correct value based on the style sheet.
Fixes: QTBUG-63381
Pick-to: 6.5 6.4 6.2
Change-Id: Ic67ce3a7cb5089f885dabfd5a1951e3029915446
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/widgets/widgets/qscrollbar.cpp')
-rw-r--r-- | src/widgets/widgets/qscrollbar.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/widgets/widgets/qscrollbar.cpp b/src/widgets/widgets/qscrollbar.cpp index ed456c56b8..28794bfdcc 100644 --- a/src/widgets/widgets/qscrollbar.cpp +++ b/src/widgets/widgets/qscrollbar.cpp @@ -189,7 +189,9 @@ void QScrollBarPrivate::setTransient(bool value) if (transient != value) { transient = value; if (q->isVisible()) { - if (q->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, q)) + QStyleOptionSlider opt; + q->initStyleOption(&opt); + if (q->style()->styleHint(QStyle::SH_ScrollBar_Transient, &opt, q)) q->update(); } else if (!transient) { q->show(); @@ -200,7 +202,9 @@ void QScrollBarPrivate::setTransient(bool value) void QScrollBarPrivate::flash() { Q_Q(QScrollBar); - if (!flashed && q->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, q)) { + QStyleOptionSlider opt; + q->initStyleOption(&opt); + if (!flashed && q->style()->styleHint(QStyle::SH_ScrollBar_Transient, &opt, q)) { flashed = true; if (!q->isVisible()) q->show(); @@ -284,7 +288,7 @@ void QScrollBar::initStyleOption(QStyleOptionSlider *option) const option->upsideDown = d->invertedAppearance; if (d->orientation == Qt::Horizontal) option->state |= QStyle::State_Horizontal; - if ((d->flashed || !d->transient) && style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, this)) + if ((d->flashed || !d->transient) && style()->styleHint(QStyle::SH_ScrollBar_Transient, option, this)) option->state |= QStyle::State_On; } @@ -341,7 +345,9 @@ void QScrollBarPrivate::init() invertedControls = true; pressedControl = hoverControl = QStyle::SC_None; pointerOutsidePressedControl = false; - transient = q->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, q); + QStyleOption opt; + opt.initFrom(q); + transient = q->style()->styleHint(QStyle::SH_ScrollBar_Transient, &opt, q); flashed = false; flashTimer = 0; q->setFocusPolicy(Qt::NoFocus); @@ -435,12 +441,17 @@ bool QScrollBar::event(QEvent *event) if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event)) d_func()->updateHoverControl(he->position().toPoint()); break; - case QEvent::StyleChange: - d_func()->setTransient(style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, this)); + case QEvent::StyleChange: { + QStyleOptionSlider opt; + initStyleOption(&opt); + d_func()->setTransient(style()->styleHint(QStyle::SH_ScrollBar_Transient, &opt, this)); break; + } case QEvent::Timer: if (static_cast<QTimerEvent *>(event)->timerId() == d->flashTimer) { - if (d->flashed && style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, this)) { + QStyleOptionSlider opt; + initStyleOption(&opt); + if (d->flashed && style()->styleHint(QStyle::SH_ScrollBar_Transient, &opt, this)) { d->flashed = false; update(); } |