summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qlistview.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-09-09 16:28:27 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-09-12 05:42:53 +0200
commit3f8c4ae047428d21303cc5e12880838236138616 (patch)
tree44395d9678a117505eff06c6edb8684706c7e1d3 /src/widgets/itemviews/qlistview.cpp
parent605d2163f1dcd7e1ad701ade913cb476b91865b1 (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/qlistview.cpp')
-rw-r--r--src/widgets/itemviews/qlistview.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 141937da75..721b9aa0d3 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -1083,7 +1083,7 @@ void QListView::paintEvent(QPaintEvent *e)
previousRow = row;
}
- d->delegateForIndex(*it)->paint(&painter, option, *it);
+ itemDelegateForIndex(*it)->paint(&painter, option, *it);
}
#if QT_CONFIG(draganddrop)
@@ -1883,14 +1883,15 @@ QModelIndex QListViewPrivate::closestIndex(const QRect &target,
QSize QListViewPrivate::itemSize(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
+ Q_Q(const QListView);
if (!uniformItemSizes) {
- const QAbstractItemDelegate *delegate = delegateForIndex(index);
+ const QAbstractItemDelegate *delegate = q->itemDelegateForIndex(index);
return delegate ? delegate->sizeHint(option, index) : QSize();
}
if (!cachedItemSize.isValid()) { // the last item is probaly the largest, so we use its size
int row = model->rowCount(root) - 1;
QModelIndex sample = model->index(row, column, root);
- const QAbstractItemDelegate *delegate = delegateForIndex(sample);
+ const QAbstractItemDelegate *delegate = q->itemDelegateForIndex(sample);
cachedItemSize = delegate ? delegate->sizeHint(option, sample) : QSize();
}
return cachedItemSize;