Add QMenu::menuInAction as a static helper
QAction::menu is deprecated, as it makes QAction (a QtGui class) depend on QtWidgets. The template hack works, but shouldn't become a permanent solution and is already deprecated. To get the QMenu out of a QAction that contains it, add a static helper to QMenu instead. QAction continues to store the menu pointer so that we don't have to use a dynamic property or an associative container in QMenu. Change-Id: Ieb6a2b1900d2fc2f16dd5a4a8ab7da98604642d3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>bb10
parent
6ab16d52d2
commit
35ddf34988
|
|
@ -1225,7 +1225,7 @@ QAction::MenuRole QAction::menuRole() const
|
|||
|
||||
/*!
|
||||
\fn QMenu *QAction::menu() const
|
||||
\deprecated
|
||||
\deprecated Use QMenu::menuForAction instead.
|
||||
|
||||
Returns the menu contained by this action.
|
||||
|
||||
|
|
|
|||
|
|
@ -1052,6 +1052,16 @@ QAction *QMenu::menuAction() const
|
|||
return d_func()->menuAction;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn static QMenu *QMenu::menuInAction(const QAction *action)
|
||||
|
||||
Returns the menu contained by \a action, or \nullptr if \a action does not
|
||||
contain a menu.
|
||||
|
||||
In widget applications, actions that contain menus can be used to create menu
|
||||
items with submenus, or inserted into toolbars to create buttons with popup menus.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\property QMenu::title
|
||||
\brief The title of the menu
|
||||
|
|
|
|||
|
|
@ -189,6 +189,8 @@ public:
|
|||
QAction *actionAt(const QPoint &) const;
|
||||
|
||||
QAction *menuAction() const;
|
||||
static QMenu *menuInAction(const QAction *action)
|
||||
{ return qobject_cast<QMenu *>(action->menuObject()); }
|
||||
|
||||
QString title() const;
|
||||
void setTitle(const QString &title);
|
||||
|
|
|
|||
Loading…
Reference in New Issue