summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <[email protected]>2024-12-02 18:42:16 +0100
committerVolker Hilsheimer <[email protected]>2025-01-20 21:03:50 +0000
commitc917d16f4b9982425b51dfc4947792e36defde35 (patch)
tree9b0911bb70d061642ee20a9d83723f53cd923994
parent2ec4c28470de115c16944653a5d4f6209452d56c (diff)
Widgets: add enum values to QStyleOptionViewItem::ViewItemFeature
Add two new enum values: IsDecoratedRootColumn: notifies the style that the current cell also contains place for the tree column branch indicator so it can e.g. properly draw rounded edges in a cell or complete row. IsDecorationForRootColumn: the item contains the information to draw the tree column branch indicator. Pick-to: 6.9 Task-number: QTBUG-131585 Change-Id: Iee2823fe3a227630f926d0448095a10fad2b0ba7 Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r--src/widgets/itemviews/qtreeview.cpp13
-rw-r--r--src/widgets/styles/qstyleoption.cpp4
-rw-r--r--src/widgets/styles/qstyleoption.h4
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp2
4 files changed, 17 insertions, 6 deletions
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp
index 0fd0572741f..2c040b2d635 100644
--- a/src/widgets/itemviews/qtreeview.cpp
+++ b/src/widgets/itemviews/qtreeview.cpp
@@ -1786,6 +1786,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option,
if (alternate) {
opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
}
+ opt.features &= ~QStyleOptionViewItem::IsDecoratedRootColumn;
/* Prior to Qt 4.3, the background of the branch (in selected state and
alternate row color was provided by the view. For backward compatibility,
@@ -1800,7 +1801,6 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option,
painter->setClipRect(QRect(position, y, width, height));
}
// draw background for the branch (selection + alternate row)
- opt.rect = branches;
// We use showDecorationSelected both to store the style hint, and to indicate
// that the entire row has to be selected (see overrides of the value if
@@ -1810,10 +1810,15 @@ 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;
+ if (opt.rect.width() > 0) {
+ // the root item also has a branch decoration
+ opt.features |= QStyleOptionViewItem::IsDecoratedRootColumn;
+ // we now want to draw the branch decoration
+ opt.features |= QStyleOptionViewItem::IsDecorationForRootColumn;
+ style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this);
+ opt.features &= ~QStyleOptionViewItem::IsDecorationForRootColumn;
+ }
// draw background of the item (only alternate row). rest of the background
// is provided by the delegate
diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp
index 27e66b7cb6c..f1fc18003c1 100644
--- a/src/widgets/styles/qstyleoption.cpp
+++ b/src/widgets/styles/qstyleoption.cpp
@@ -3093,6 +3093,10 @@ QStyleOptionViewItem::QStyleOptionViewItem(int version)
\value HasCheckIndicator Indicates that the item has a check state indicator.
\value HasDisplay Indicates that the item has a display role.
\value HasDecoration Indicates that the item has a decoration role.
+ \value [since 6.9] IsDecoratedRootColumn Indicates that the item has a tree view branch
+ part for painting.
+ \value [since 6.9] IsDecorationForRootColumn Indicates that the item contains the
+ information to draw the tree view branch part.
*/
/*!
diff --git a/src/widgets/styles/qstyleoption.h b/src/widgets/styles/qstyleoption.h
index d63d1c9a0e1..49b37132de3 100644
--- a/src/widgets/styles/qstyleoption.h
+++ b/src/widgets/styles/qstyleoption.h
@@ -403,7 +403,9 @@ public:
Alternate = 0x02,
HasCheckIndicator = 0x04,
HasDisplay = 0x08,
- HasDecoration = 0x10
+ HasDecoration = 0x10,
+ IsDecoratedRootColumn = 0x20,
+ IsDecorationForRootColumn = 0x40,
};
Q_DECLARE_FLAGS(ViewItemFeatures, ViewItemFeature)
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 468c7a51550..f8b3ff027ec 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -4875,7 +4875,7 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op
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 &&
+ if (vopt->features & QStyleOptionViewItem::IsDecorationForRootColumn &&
(vopt->viewItemPosition == QStyleOptionViewItem::Beginning ||
vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne) && rule.hasBorder()) {
if (rule.hasDrawable()) {