From 56da533b45e2785e8fd54ef6fcddb7b973c665bf Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 23 Nov 2021 17:05:05 +0100 Subject: Never handle scrollbars styled with box or border changes as transient If scrollbars are styled with a style sheet that includes a box or removes off the native border, then we never treat them as transient or overlapping. Otherwise, the layout logic in QAbstractScrollArea will show them on top of the viewport, overlapping the content. Add case to the style sheet test baseline test. It's a test for scrollbars in a scroll area, rather than a test for the styling of the scrollbars themselves. Fixes: QTBUG-98289 Pick-to: 6.2 Change-Id: Ic53ad248b3eedd54722ac7b2fe5256a27092dbc1 Reviewed-by: Richard Moe Gustavsen --- src/widgets/styles/qstylesheetstyle.cpp | 10 +++ .../stylesheet/qss/qscrollarea/no_border.qss | 1 + .../qss/qscrollarea/styled_scrollbars.qss | 72 ++++++++++++++++++++++ .../stylesheet/tst_baseline_stylesheet.cpp | 19 ++++++ 4 files changed, 102 insertions(+) create mode 100644 tests/baseline/stylesheet/qss/qscrollarea/no_border.qss create mode 100644 tests/baseline/stylesheet/qss/qscrollarea/styled_scrollbars.qss diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 0784f61747..1449def8c5 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -5065,8 +5065,14 @@ int QStyleSheetStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const if (!rule.hasNativeBorder() || rule.hasBox()) return 0; break; + + case PM_ScrollView_ScrollBarOverlap: + if (!rule.hasNativeBorder() || rule.hasBox()) + return 0; + break; #endif // QT_CONFIG(scrollbar) + case PM_ProgressBarChunkWidth: subRule = renderRule(w, opt, PseudoElement_ProgressBarChunk); if (subRule.hasContentsSize()) { @@ -5659,6 +5665,10 @@ int QStyleSheetStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWi case SH_ItemView_PaintAlternatingRowColorsForEmptyArea: s = QLatin1String("paint-alternating-row-colors-for-empty-area"); break; case SH_TitleBar_ShowToolTipsOnButtons: s = QLatin1String("titlebar-show-tooltips-on-buttons"); break; case SH_Widget_Animation_Duration: s = QLatin1String("widget-animation-duration"); break; + case SH_ScrollBar_Transient: + if (!rule.hasNativeBorder() || rule.hasBox()) + return 0; + break; default: break; } if (!s.isEmpty() && rule.hasStyleHint(s)) { diff --git a/tests/baseline/stylesheet/qss/qscrollarea/no_border.qss b/tests/baseline/stylesheet/qss/qscrollarea/no_border.qss new file mode 100644 index 0000000000..0c9744de7c --- /dev/null +++ b/tests/baseline/stylesheet/qss/qscrollarea/no_border.qss @@ -0,0 +1 @@ +border: none diff --git a/tests/baseline/stylesheet/qss/qscrollarea/styled_scrollbars.qss b/tests/baseline/stylesheet/qss/qscrollarea/styled_scrollbars.qss new file mode 100644 index 0000000000..94fa3db183 --- /dev/null +++ b/tests/baseline/stylesheet/qss/qscrollarea/styled_scrollbars.qss @@ -0,0 +1,72 @@ +QScrollBar:horizontal { + border: 2px solid grey; + background: #32CC99; + height: 15px; + margin: 0px 20px 0 20px; +} +QScrollBar::handle:horizontal { + background: white; + min-width: 20px; +} +QScrollBar::add-line:horizontal { + border: 2px solid grey; + background: #32CC99; + width: 20px; + subcontrol-position: right; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:horizontal { + border: 2px solid grey; + background: #32CC99; + width: 20px; + subcontrol-position: left; + subcontrol-origin: margin; +} + +QScrollBar:left-arrow:horizontal, QScrollBar::right-arrow:horizontal { + border: 2px solid grey; + width: 3px; + height: 3px; + background: white; +} + +QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal { + background: none; +} + +QScrollBar:vertical { + border: 2px solid grey; + background: #32CC99; + width: 15px; + margin: 22px 0 22px 0; +} +QScrollBar::handle:vertical { + background: white; + min-height: 20px; +} +QScrollBar::add-line:vertical { + border: 2px solid grey; + background: #32CC99; + height: 20px; + subcontrol-position: bottom; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:vertical { + border: 2px solid grey; + background: #32CC99; + height: 20px; + subcontrol-position: top; + subcontrol-origin: margin; +} +QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { + border: 2px solid grey; + width: 3px; + height: 3px; + background: white; +} + +QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { + background: none; +} diff --git a/tests/baseline/stylesheet/tst_baseline_stylesheet.cpp b/tests/baseline/stylesheet/tst_baseline_stylesheet.cpp index fe666d83e8..99b21b4bb5 100644 --- a/tests/baseline/stylesheet/tst_baseline_stylesheet.cpp +++ b/tests/baseline/stylesheet/tst_baseline_stylesheet.cpp @@ -46,6 +46,9 @@ private slots: void tst_QToolButton_data(); void tst_QToolButton(); + void tst_QScrollArea_data(); + void tst_QScrollArea(); + private: QDir styleSheetDir; }; @@ -151,6 +154,22 @@ void tst_Stylesheet::tst_QToolButton() QBASELINE_TEST(takeSnapshot()); } +void tst_Stylesheet::tst_QScrollArea_data() +{ + loadTestFiles(); +} + +void tst_Stylesheet::tst_QScrollArea() +{ + QHBoxLayout *layout = new QHBoxLayout; + QTableWidget *table = new QTableWidget(20, 20); + layout->addWidget(table); + testWindow()->setLayout(layout); + + makeVisible(); + QBASELINE_TEST(takeSnapshot()); +} + #define main _realmain QTEST_MAIN(tst_Stylesheet) #undef main -- cgit v1.2.3