diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-09-09 16:28:27 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-09-12 05:42:53 +0200 |
commit | 3f8c4ae047428d21303cc5e12880838236138616 (patch) | |
tree | 44395d9678a117505eff06c6edb8684706c7e1d3 /src/widgets/itemviews/qtreeview.cpp | |
parent | 605d2163f1dcd7e1ad701ade913cb476b91865b1 (diff) |
QAbstractItemView: add virtual itemDelegateForIndex
and obsolete itemDelegate(index), which the new function replaces.
This allows itemviews to override the item delegate per index. The
existing APIs to set delegates for rows and columns doesn't work for
tree views, or other views where the delegate should depend on the
parent index as well.
Adjust all itemview code that accessed the QAIVPrivate's relevant
data structures directly to go through the virtual function.
[ChangeLog][QtWidgets][QAbstractItemView] The
itemDelegate(QModelIndex) member function has been made obsolete,
and has been replaced by a new virtual
itemDelegateForIndex(QModelIndex) member function that can be
overridden to give subclasses control over which item delegate
should be used for an index.
Change-Id: Ib03529c38797386d3a1d4cf3c5646e911d95daf5
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Diffstat (limited to 'src/widgets/itemviews/qtreeview.cpp')
-rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 56df15f237..dedc27501f 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -1621,6 +1621,7 @@ void QTreeViewPrivate::calcLogicalIndices( */ int QTreeViewPrivate::widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option, int i) const { + Q_Q(const QTreeView); QWidget *editor = editorForIndex(index).widget.data(); if (editor && persistent.contains(editor)) { hint = qMax(hint, editor->sizeHint().width()); @@ -1628,7 +1629,7 @@ int QTreeViewPrivate::widthHintForIndex(const QModelIndex &index, int hint, cons int max = editor->maximumSize().width(); hint = qBound(min, hint, max); } - int xhint = delegateForIndex(index)->sizeHint(option, index).width(); + int xhint = q->itemDelegateForIndex(index)->sizeHint(option, index).width(); hint = qMax(hint, xhint + (isTreePosition(index.column()) ? indentationForItem(i) : 0)); return hint; } @@ -1802,7 +1803,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, opt.state = oldState; } - d->delegateForIndex(modelIndex)->paint(painter, opt, modelIndex); + itemDelegateForIndex(modelIndex)->paint(painter, opt, modelIndex); } if (currentRowHasFocus) { @@ -3015,7 +3016,7 @@ int QTreeView::indexRowSizeHint(const QModelIndex &index) const int max = editor->maximumSize().height(); height = qBound(min, height, max); } - int hint = d->delegateForIndex(idx)->sizeHint(option, idx).height(); + int hint = itemDelegateForIndex(idx)->sizeHint(option, idx).height(); height = qMax(height, hint); } } @@ -3274,7 +3275,7 @@ QPixmap QTreeViewPrivate::renderTreeToPixmapForAnimation(const QRect &rect) cons option.rect = q->visualRect(index); if (option.rect.isValid()) { - if (QAbstractItemDelegate *delegate = delegateForIndex(index)) + if (QAbstractItemDelegate *delegate = q->itemDelegateForIndex(index)) delegate->updateEditorGeometry(editor, option, index); const QPoint pos = editor->pos(); |