diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-05-04 03:04:57 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-05-04 03:04:57 +0200 |
commit | 324ec97aa256549c56d506fd96c1e06c35fed1ae (patch) | |
tree | a3cdf92830cf8cd7e80b6de4eeda8cd847540919 /src/quicktemplates2/qquickmenu.cpp | |
parent | 8301071b25f50a119822519f08af9595b95430fc (diff) | |
parent | 0525d640cd11ddced2ec418be182c585204fc45f (diff) |
Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: I1ec3d930d4131ba6d1de687250c0f4f698946af4
Diffstat (limited to 'src/quicktemplates2/qquickmenu.cpp')
-rw-r--r-- | src/quicktemplates2/qquickmenu.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquickmenu.cpp b/src/quicktemplates2/qquickmenu.cpp index f91d15a5..aa44e845 100644 --- a/src/quicktemplates2/qquickmenu.cpp +++ b/src/quicktemplates2/qquickmenu.cpp @@ -213,6 +213,7 @@ void QQuickMenuPrivate::insertItem(int index, QQuickItem *item) if (complete) resizeItem(item); QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent); + QQuickItemPrivate::get(item)->updateOrAddGeometryChangeListener(this, QQuickGeometryChange::Width); contentModel->insert(index, item); QQuickMenuItem *menuItem = qobject_cast<QQuickMenuItem *>(item); @@ -237,6 +238,7 @@ void QQuickMenuPrivate::removeItem(int index, QQuickItem *item) contentData.removeOne(item); QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent); + QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Geometry); item->setParentItem(nullptr); contentModel->remove(index); @@ -358,10 +360,20 @@ void QQuickMenuPrivate::itemDestroyed(QQuickItem *item) removeItem(index, item); } -void QQuickMenuPrivate::itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &) +void QQuickMenuPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange, const QRectF &) { - if (complete) + if (!complete) + return; + + if (item == contentItem) { + // The contentItem's geometry changed, so resize any items + // that don't have explicit widths set so that they fill the width of the menu. resizeItems(); + } else { + // The geometry of an item in the menu changed. If the item + // doesn't have an explicit width set, make it fill the width of the menu. + resizeItem(item); + } } QQuickPopupPositioner *QQuickMenuPrivate::getPositioner() @@ -1382,10 +1394,14 @@ void QQuickMenu::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) Q_D(QQuickMenu); QQuickPopup::contentItemChange(newItem, oldItem); - if (oldItem) + if (oldItem) { QQuickItemPrivate::get(oldItem)->removeItemChangeListener(d, QQuickItemPrivate::Children); - if (newItem) + QQuickItemPrivate::get(oldItem)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + } + if (newItem) { QQuickItemPrivate::get(newItem)->addItemChangeListener(d, QQuickItemPrivate::Children); + QQuickItemPrivate::get(newItem)->updateOrAddGeometryChangeListener(d, QQuickGeometryChange::Width); + } d->contentItem = newItem; } |