简体   繁体   English

如何获得QToolBar / QDockWidget上下文菜单操作?

[英]How to get QToolBar / QDockWidget context menu actions?

When QToolBar and QDockWidget widgets are used, they automatically generate a context menu which allows you to show/hide these dock and toolbar widgets (see the screenshot ). 使用QToolBarQDockWidget小部件时,它们会自动生成一个上下文菜单,该菜单使您可以显示/隐藏这些Dock和工具栏小部件(请参见屏幕截图 )。

How can I get these context menu actions? 如何获得这些上下文菜单操作?

Usage example : Eg, I want to add the same actions (to show/hide docks and toolbars), to the "Window" QMenu in the menu bar without manually repeating the previously mentioned context menu. 使用示例 :例如,我想在菜单栏中的“窗口” QMenu中添加相同的操作(以显示/隐藏停靠栏和工具栏),而无需手动重复上述上下文菜单。

Found the answer. 找到了答案。

The mentioned context menu which contains automatically generated actions to show/hide dock widgets and toolbars is actually handled by the QMainWindow class. 提到的上下文菜单实际上包含QMainWindow类,该上下文菜单包含自动生成的用于显示/隐藏停靠小部件和工具栏的动作。 It has createPopupMenu() method which generates this list. 它具有createPopupMenu()方法来生成此列表。

So this is how to get the main window context menu actions: 因此,这是获取主窗口上下文菜单操作的方法:

QList<QAction *> actions = createPopupMenu()->actions();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM