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 <volker.hilsheimer@qt.io>
This commit is contained in:
Christian Ehrlicher 2024-12-02 18:42:16 +01:00 committed by Volker Hilsheimer
parent 2ec4c28470
commit c917d16f4b
4 changed files with 17 additions and 6 deletions

View File

@ -1786,6 +1786,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option,
if (alternate) { if (alternate) {
opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1); 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 /* 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, 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)); painter->setClipRect(QRect(position, y, width, height));
} }
// draw background for the branch (selection + alternate row) // draw background for the branch (selection + alternate row)
opt.rect = branches;
// We use showDecorationSelected both to store the style hint, and to indicate // 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 // 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; const bool oldShowDecorationSelected = opt.showDecorationSelected;
opt.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, opt.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected,
&opt, this); &opt, this);
opt.features |= QStyleOptionViewItem::HasDecoration;
opt.rect = branches; opt.rect = branches;
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); style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this);
opt.features &= ~QStyleOptionViewItem::HasDecoration; opt.features &= ~QStyleOptionViewItem::IsDecorationForRootColumn;
}
// draw background of the item (only alternate row). rest of the background // draw background of the item (only alternate row). rest of the background
// is provided by the delegate // is provided by the delegate

View File

@ -3093,6 +3093,10 @@ QStyleOptionViewItem::QStyleOptionViewItem(int version)
\value HasCheckIndicator Indicates that the item has a check state indicator. \value HasCheckIndicator Indicates that the item has a check state indicator.
\value HasDisplay Indicates that the item has a display role. \value HasDisplay Indicates that the item has a display role.
\value HasDecoration Indicates that the item has a decoration 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.
*/ */
/*! /*!

View File

@ -403,7 +403,9 @@ public:
Alternate = 0x02, Alternate = 0x02,
HasCheckIndicator = 0x04, HasCheckIndicator = 0x04,
HasDisplay = 0x08, HasDisplay = 0x08,
HasDecoration = 0x10 HasDecoration = 0x10,
IsDecoratedRootColumn = 0x20,
IsDecorationForRootColumn = 0x40,
}; };
Q_DECLARE_FLAGS(ViewItemFeatures, ViewItemFeature) Q_DECLARE_FLAGS(ViewItemFeatures, ViewItemFeature)

View File

@ -4875,7 +4875,7 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op
if (rule.background()->brush.color().alpha() != 1.0) if (rule.background()->brush.color().alpha() != 1.0)
baseStyle()->drawPrimitive(pe, opt, p, w); baseStyle()->drawPrimitive(pe, opt, p, w);
// Skip border for the branch and draw only the brackground // 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::Beginning ||
vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne) && rule.hasBorder()) { vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne) && rule.hasBorder()) {
if (rule.hasDrawable()) { if (rule.hasDrawable()) {