StyleSheet/QTreeView: draw empty area and background of semi-transparent items

After 3ca615d9735f7ddb8e2ae5c13e5effd419a56300, the style sheet style
will not draw rows unless the item has a border. Otherwise, it will
assume that the item drawing later on will fill the background anyway.
We also never painted the background for empty rows.

However, if the item's background is semi-transparent, then the row
needs to be drawn first, so that the correct background shows through.
And for empty rows, we need to draw just the background. This is
especially important for trees with alternate background colors.

Add baseline test case for this particular combination. This will result
in a minor change to the results of the existing
transparentBackgroundNoBorderForBranchIndicator test case, where now the
background is drawn behind the indicator area when the item's background
is semi-transparent. I don't think this is a bug though.

Pick-to: 6.8
Fixes: QTBUG-123632
Change-Id: I2cd4efb748aaefc03a3b576458b750ee47479e97
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
This commit is contained in:
Volker Hilsheimer 2024-11-05 17:03:45 +01:00
parent f5cad8035d
commit b780eaf6a0
2 changed files with 21 additions and 5 deletions

View File

@ -4870,11 +4870,15 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op
// only indirectly through the background of the item. To get the
// same background for all parts drawn by QTreeView, we have to
// use the background rule for the item here.
if (renderRule(w, opt, PseudoElement_ViewItem).hasBackground()) {
pseudoElement = PseudoElement_ViewItem;
// Skip border for the branch and draw only the brackground
if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
QRenderRule rule = renderRule(w, opt, PseudoElement_ViewItem);
if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
// default handling for drawing empty space
if (vopt->viewItemPosition == QStyleOptionViewItem::Invalid)
break;
if (QRenderRule rule = renderRule(w, opt, PseudoElement_ViewItem); rule.hasBackground()) {
// if the item background is not fully opaque, then we have to paint the row
if (rule.background()->brush.color().alpha() != 1.0)
baseStyle()->drawPrimitive(pe, opt, p, w);
// Skip border for the branch and draw only the brackground
if (vopt->features & QStyleOptionViewItem::HasDecoration &&
(vopt->viewItemPosition == QStyleOptionViewItem::Beginning ||
vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne) && rule.hasBorder()) {
@ -4886,6 +4890,7 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op
}
return;
}
pseudoElement = PseudoElement_ViewItem;
}
}
break;

View File

@ -0,0 +1,11 @@
QTreeView {
qproperty-alternatingRowColors: true;
alternate-background-color: fuchsia;
background-color: orange;
}
QTreeView::item {
background-color: "#A00000FF";
color: #3C3C3C;
padding: 2px;
}