diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-07-18 17:12:14 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-07-19 09:05:30 +0000 |
commit | b5d7be57ccb8ca60590ed30d04271e76acc84029 (patch) | |
tree | 2bea23bfdd86ba494f36aaa481cdbd14a0583d35 /src/quick/items | |
parent | 379ba8640a9cf7e43e848eb07c11989f0f4f3ddd (diff) |
QQuickTableView: set delegate parent early-on
Set the parent before bindings are evaluated.
Change-Id: I370524fe32c66699bd73aafeac55c58667b4dff1
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quick/items')
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index db1d262df7..7b2070ff52 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -333,7 +333,13 @@ FxTableItem *QQuickTableViewPrivate::createFxTableItem(const QPoint &cell, QQmlI ownItem = true; } - item->setParentItem(q->contentItem()); + if (ownItem) { + // Parent item is normally set early on from initItemCallback (to + // allow bindings to the parent property). But if we created the item + // within this function, we need to set it explicit. + item->setParentItem(q->contentItem()); + } + Q_TABLEVIEW_ASSERT(item->parentItem() == q->contentItem(), item->parentItem()); FxTableItem *fxTableItem = new FxTableItem(item, q, ownItem); fxTableItem->setVisible(false); @@ -1088,11 +1094,13 @@ void QQuickTableViewPrivate::itemCreatedCallback(int modelIndex, QObject*) void QQuickTableViewPrivate::initItemCallback(int modelIndex, QObject *object) { Q_UNUSED(modelIndex); - auto attached = getAttachedObject(object); - if (!attached) - return; + Q_Q(QQuickTableView); + + if (auto item = qmlobject_cast<QQuickItem*>(object)) + item->setParentItem(q->contentItem()); - attached->setTableView(q_func()); + if (auto attached = getAttachedObject(object)) + attached->setTableView(q); } void QQuickTableViewPrivate::connectToModel() |