c z
c z

Reputation: 9027

Make Qt menu appear programmatically

I have a QMenu in a QMenuBar.

I can make the QMenu appear via QMenu.show() QMenu.exec() and QMenu.showTearOffMenu(), but these show the menu at the top-left of the screen, at a prespecified position, or under the mouse. I want the menu to appear in its usual position (under the QMenuBar). Is this possible (in any Qt language)?

Upvotes: 0

Views: 451

Answers (2)

Nimish Bansal
Nimish Bansal

Reputation: 1759

You could simply use

your_menuBar.addMenu(your_menu
self.setMenuBar(your_menuBar)

where self will correspond to QMainWindow

Refer setMenuBar

Sets the menu bar for the main window to menuBar.

http://doc.qt.io/qt-5/qmainwindow.html#setMenuBar

Upvotes: 1

Simon
Simon

Reputation: 1590

In Qt, you can use the position of your menu bar and then to open the menu on that position:

poMenu->exec(mapToGlobal(m_poMenuBar->rect().bottomLeft()));

Upvotes: 0

Related Questions