0

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).

How can I get these context menu actions?

Usage example: E.g., 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.

John Doe
  • 555
  • 6
  • 17
  • i found somewhat similar issue [here](https://forum.qt.io/topic/9578/solved-qtoolbar-inside-of-the-qdockwidget/2) – MarKS Mar 13 '18 at 15:36
  • @MarKS Thanks, but that is a bit different issue. I need to get the **context** menu (right mouse click) which is automatically generated by `QToolBar` or `QDockWidget`. – John Doe Mar 13 '18 at 15:45
  • 1
    @JohnDoe your question is not so clear...if you want to add new entries to your contextMenu of your `QToolBar` maybe you can check [this](https://stackoverflow.com/questions/38035921/how-to-add-an-entry-to-toolbar-context-menu-in-qt/38037698) – MarKS Mar 13 '18 at 15:59
  • 1
    I don't think there is anything wrong with this question. John asked for a feature that is not documented very well so where should he get any code from when he needs that exact code. He even provided an example for what it could be used for. – Tim Woocker May 16 '19 at 13:11

1 Answers1

3

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. It has createPopupMenu() method which generates this list.

So this is how to get the main window context menu actions:

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

John Doe
  • 555
  • 6
  • 17