diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 1ae81023c53..621e9f220aa 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -1821,7 +1821,10 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, const bool oldShowDecorationSelected = opt.showDecorationSelected; opt.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, &opt, this); + opt.features |= QStyleOptionViewItem::HasDecoration; + opt.rect = branches; style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this); + opt.features &= ~QStyleOptionViewItem::HasDecoration; // draw background of the item (only alternate row). rest of the background // is provided by the delegate diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 655b2246176..004326e0a44 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -4844,8 +4844,24 @@ 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()) + 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 (vopt->features & QStyleOptionViewItem::HasDecoration && + (vopt->viewItemPosition == QStyleOptionViewItem::Beginning || + vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne) && rule.hasBorder()) { + if (rule.hasDrawable()) { + rule.drawBackground(p, rect); + rule.drawImage(p, rule.contentsRect(rect)); + } else { + baseStyle()->drawPrimitive(pe, opt, p, w); + } + return; + } + } + } break; case PE_PanelItemViewItem: pseudoElement = PseudoElement_ViewItem; diff --git a/tests/baseline/stylesheet/qss/qtreeview/NoBackgroundNoBorderForBranchIndicator.qss b/tests/baseline/stylesheet/qss/qtreeview/NoBackgroundNoBorderForBranchIndicator.qss new file mode 100644 index 00000000000..dda89c4b34b --- /dev/null +++ b/tests/baseline/stylesheet/qss/qtreeview/NoBackgroundNoBorderForBranchIndicator.qss @@ -0,0 +1,3 @@ +QTreeWidget::item { + border: 1px solid #32ff44; +} diff --git a/tests/baseline/stylesheet/qss/qtreeview/transparentBackgroundNoBorderForBranchIndicator.qss b/tests/baseline/stylesheet/qss/qtreeview/transparentBackgroundNoBorderForBranchIndicator.qss new file mode 100644 index 00000000000..6ed7602fa00 --- /dev/null +++ b/tests/baseline/stylesheet/qss/qtreeview/transparentBackgroundNoBorderForBranchIndicator.qss @@ -0,0 +1,4 @@ +QTreeWidget::item { + border: 1px solid #32ff44; + background-color: transparent; +} diff --git a/tests/baseline/stylesheet/qss/qtreeview/validBackgroundNoBorderForBranchIndicator.qss b/tests/baseline/stylesheet/qss/qtreeview/validBackgroundNoBorderForBranchIndicator.qss new file mode 100644 index 00000000000..d5e759d515d --- /dev/null +++ b/tests/baseline/stylesheet/qss/qtreeview/validBackgroundNoBorderForBranchIndicator.qss @@ -0,0 +1,4 @@ +QTreeWidget::item { + border: 1px solid #32ff44; + background-color: orange; +}