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 <richard.gustavsen@qt.io>
This commit is contained in:
Volker Hilsheimer 2021-11-23 17:05:05 +01:00
parent 8fbedf2196
commit 56da533b45
4 changed files with 102 additions and 0 deletions

View File

@ -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)) {

View File

@ -0,0 +1 @@
border: none

View File

@ -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;
}

View File

@ -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