diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 363662585d3..edce3f3eeb2 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -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(opt)) { - QRenderRule rule = renderRule(w, opt, PseudoElement_ViewItem); + if (const QStyleOptionViewItem *vopt = qstyleoption_cast(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; diff --git a/tests/baseline/stylesheet/qss/qtreeview/transparentItemBackgroundOnAlternating.qss b/tests/baseline/stylesheet/qss/qtreeview/transparentItemBackgroundOnAlternating.qss new file mode 100644 index 00000000000..d78be3af800 --- /dev/null +++ b/tests/baseline/stylesheet/qss/qtreeview/transparentItemBackgroundOnAlternating.qss @@ -0,0 +1,11 @@ +QTreeView { + qproperty-alternatingRowColors: true; + alternate-background-color: fuchsia; + background-color: orange; +} + +QTreeView::item { + background-color: "#A00000FF"; + color: #3C3C3C; + padding: 2px; +}