diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 2f6546b767..6cf05c411f 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -1659,8 +1659,11 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, } } - // ### special case: treeviews with multiple columns draw - // the selections differently than with only one column + // ### special case: if we select entire rows, then we need to draw the + // selection in the first column all the way to the second column, rather + // than just around the item text. We abuse showDecorationSelected to + // indicate this to the style. Below we will reset this value temporarily + // to only respect the styleHint while we are rendering the decoration. opt.showDecorationSelected = (d->selectionBehavior & SelectRows) || option.showDecorationSelected; @@ -1745,8 +1748,16 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, } // draw background for the branch (selection + alternate row) opt.rect = branches; - if (style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, &opt, this)) - style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this); + + // 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 + // selectionBehavior == SelectRow). + // While we are only painting the background we don't care for the + // selectionBehavior factor, so respect only the style value, and reset later. + const bool oldShowDecorationSelected = opt.showDecorationSelected; + opt.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, + &opt, this); + style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this); // draw background of the item (only alternate row). rest of the background // is provided by the delegate @@ -1755,6 +1766,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, opt.rect.setRect(reverse ? position : i + position, y, width - i, height); style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this); opt.state = oldState; + opt.showDecorationSelected = oldShowDecorationSelected; if (d->indent != 0) drawBranches(painter, branches, index); diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 2cb9bc00ba..657f540324 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -657,7 +657,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active)) cg = QPalette::Inactive; - if ((vopt->state & QStyle::State_Selected) && proxy()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, opt, widget)) + if ((vopt->state & QStyle::State_Selected) && vopt->showDecorationSelected) p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight)); else if (vopt->features & QStyleOptionViewItem::Alternate) p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::AlternateBase));