diff options
author | Richard Moe Gustavsen <[email protected]> | 2025-06-04 14:03:00 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <[email protected]> | 2025-06-05 17:10:21 +0200 |
commit | 1c121ea7ab4791bf26759013c1a77eac9d76e3c3 (patch) | |
tree | 4d246117b1cf915ce4109b885571068cc52aa32b | |
parent | 1b07c1b8d66eb6d630c2744039c687fdcccfaa66 (diff) |
As it stood, we would search for a label's buddy from the top level
widget and down, based on the object name. The problem with that approach
is that since the same form can be instantiated onto multiple widgets
inside the same window, there can exist multiple buddies with the same
name as well. As a result, the form builder would end up resolving the
same buddy instance for the all the form instances.
Rather than searching for the buddy top-down, this patch will instead
search for it bottom-up. We assume then, that the buddy closest to
the label is the correct one to use.
Fixes: QTBUG-96693
Pick-to: 6.10 6.9 6.8 6.5
Change-Id: Iae7c8865563304810ed5f905c6ad45d7b796b7a5
Reviewed-by: Friedemann Kleint <[email protected]>
-rw-r--r-- | src/designer/src/lib/uilib/formbuilderextra.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/designer/src/lib/uilib/formbuilderextra.cpp b/src/designer/src/lib/uilib/formbuilderextra.cpp index 5d5a14acf..0507573e3 100644 --- a/src/designer/src/lib/uilib/formbuilderextra.cpp +++ b/src/designer/src/lib/uilib/formbuilderextra.cpp @@ -174,7 +174,18 @@ bool QFormBuilderExtra::applyBuddy(const QString &buddyName, BuddyMode applyMode return false; } - const QWidgetList widgets = label->topLevelWidget()->findChildren<QWidget*>(buddyName); + // QTBUG-96693: Because the same form can be instantiated on multiple + // widgets, when for example using a form for custom widgets, there can + // exist multiple widgets with the same buddy name in the window. Since + // the buddy closest to the label is the correct one to use, we search + // for the buddy bottom-up rather than top-down. + QWidgetList widgets; + QWidget *parent = label->parentWidget(); + while (parent && widgets.isEmpty()) { + widgets = parent->findChildren<QWidget*>(buddyName); + parent = parent->parentWidget(); + } + if (widgets.isEmpty()) { label->setBuddy(nullptr); return false; |