I use Qt4 QPushButton
with QMenu
in it (set by setMenu()
). I need to show this menu when some unrelated event occurs.
Method QPushButton::showMenu()
does this, but it blocks until user closes the menu.
QMenu::show()
also does this, but it shows the menu in the top left corner of the screen.
How can I programmatically make the menu show up properly positioned, and without blocking?
No, I didn't like the suggested solutions, because QPushButton is supposed to manage the menu position, not the caller.
So I decided to post mouse down/up events to this QPushButton widget, simulating what the user does. This did the trick. This is a hack to compensate for the missing functionality in Qt.
You can use
So
QMenu
isQWidget
. So you can callmove()
beforeshow()
.