aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates/qquickcontainer.cpp
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2026-09-03 12:35:56 +0300
committerTarja Sundqvist <tarja.sundqvist@qt.io>2026-09-03 12:35:56 +0300
commit7ed17317a5013b1ab885ecc4ac61fb0ed3c1ab35 (patch)
tree7c208fe854d7dcfd7421c2ea20e3cd8a0812adfe /src/quicktemplates/qquickcontainer.cpp
parent175e30c1a74c2b4efa5a6fe5c45d289660b51d2f (diff)
parent2d9e5e76640cd16724ec2fef20d60109537be0bd (diff)
Merge tag 'v6.5.10-lts-lgpl' into 6.56.5
Qt 6.5.10-lts-lgpl release
Diffstat (limited to 'src/quicktemplates/qquickcontainer.cpp')
-rw-r--r--src/quicktemplates/qquickcontainer.cpp40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/quicktemplates/qquickcontainer.cpp b/src/quicktemplates/qquickcontainer.cpp
index 9d48f3b3a1..499fd621d6 100644
--- a/src/quicktemplates/qquickcontainer.cpp
+++ b/src/quicktemplates/qquickcontainer.cpp
@@ -299,15 +299,37 @@ void QQuickContainerPrivate::reorderItems()
if (!contentItem)
return;
- QList<QQuickItem *> siblings = effectiveContentItem(contentItem)->childItems();
-
- int to = 0;
- for (int i = 0; i < siblings.size(); ++i) {
- QQuickItem* sibling = siblings.at(i);
- if (QQuickItemPrivate::get(sibling)->isTransparentForPositioner())
- continue;
- int index = contentModel->indexOf(sibling, nullptr);
- q->moveItem(index, to++);
+ // The item view eventually reparents all the items of the content model
+ // from the container. At this stage (during component complete), however, due
+ // to optimisation strategies in the item views, this doesn't happen when the
+ // visible area of the item view is less than the total content width of the items
+ // within the content model. This can cause issues while reordering. Thus, it's
+ // better to skip reordering the item within the content model once it's known
+ // that it will be reparented to the item views.
+ bool allowReorder = true;
+ if (!qobject_cast<QQuickFlickable *>(contentItem)) {
+ for (int index = 0; index < contentModel->count(); index++) {
+ if (const auto *item = qobject_cast<QQuickItem *>(contentModel->get(index))) {
+ const auto *parentItem = item->parentItem();
+ if (parentItem && !qobject_cast<QQuickItemView *>(parentItem->parentItem())) {
+ allowReorder = false;
+ break;
+ }
+ }
+ }
+ }
+
+ if (allowReorder) {
+ QList<QQuickItem *> siblings = effectiveContentItem(contentItem)->childItems();
+ int to = 0;
+ for (int i = 0; i < siblings.size(); ++i) {
+ QQuickItem* sibling = siblings.at(i);
+ if (QQuickItemPrivate::get(sibling)->isTransparentForPositioner())
+ continue;
+ const int index = contentModel->indexOf(sibling, nullptr);
+ if (index >= 0)
+ q->moveItem(index, to++);
+ }
}
}