diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp index 98cbc9c3d59..9dbe42519da 100644 --- a/src/gui/kernel/qaction.cpp +++ b/src/gui/kernel/qaction.cpp @@ -514,14 +514,14 @@ QList QAction::associatedObjects() const /*! \fn QWidget *QAction::parentWidget() const - \deprecated Use parent() with qobject_cast() instead. + \deprecated [6.0] Use parent() with qobject_cast() instead. Returns the parent widget. */ /*! \fn QList QAction::associatedWidgets() const - \deprecated Use associatedObjects() with qobject_cast() instead. + \deprecated [6.0] Use associatedObjects() with qobject_cast() instead. Returns a list of widgets this action has been added to. @@ -530,7 +530,7 @@ QList QAction::associatedObjects() const /*! \fn QList QAction::associatedGraphicsWidgets() const - \deprecated Use associatedObjects() with qobject_cast() instead. + \deprecated [6.0] Use associatedObjects() with qobject_cast() instead. Returns a list of graphics widgets this action has been added to. diff --git a/src/gui/kernel/qaction.h b/src/gui/kernel/qaction.h index cc854666144..8d770301484 100644 --- a/src/gui/kernel/qaction.h +++ b/src/gui/kernel/qaction.h @@ -84,6 +84,7 @@ public: QWidget, QMenu, and QGraphicsWidget can be expected to be fully defined. */ template + QT_DEPRECATED_VERSION_X_6_0("Use parent() with qobject_cast() instead") T parentWidget() const { auto result = parent(); @@ -93,6 +94,7 @@ public: } template + QT_DEPRECATED_VERSION_X_6_0("Use associatedObjects() with qobject_cast() instead") QList associatedWidgets() const { QList result; @@ -102,6 +104,7 @@ public: return result; } template + QT_DEPRECATED_VERSION_X_6_0("Use associatedObjects() with qobject_cast() instead") QList associatedGraphicsWidgets() const { QList result; diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 93f8610801e..eaca88dfa7a 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -215,13 +215,21 @@ void QMenuPrivate::syncPlatformMenu() platformMenu->setEnabled(q->isEnabled()); } +static QWidget *getParentWidget(const QAction *action) +{ + auto result = action->parent(); + while (result && !qobject_cast(result)) + result = result->parent(); + return static_cast(result); +} + void QMenuPrivate::copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item) { item->setText(action->text()); item->setIsSeparator(action->isSeparator()); if (action->isIconVisibleInMenu()) { item->setIcon(action->icon()); - if (QWidget *w = action->parentWidget()) { + if (QWidget *w = getParentWidget(action)) { QStyleOption opt; opt.initFrom(w); item->setIconSize(w->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, w)); diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 9719aefe7b2..b1928e37857 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -4671,7 +4671,7 @@ void tst_QLineEdit::sideWidgets() template T *findAssociatedWidget(const QAction *a) { - foreach (QWidget *w, a->associatedWidgets()) { + foreach (QObject *w, a->associatedObjects()) { if (T *result = qobject_cast(w)) return result; }