How to unset QMenu from QPushButton?
Solved
Qt 6
-
In order to create a popup menu and then assign it to a QPushButton, we make use of
QPushButton->setMenu(QMenu *menu)
but if once you have assigned the menu to the button and you want to remove the menu item from the button, how could you do this?
Also, once I use
setMenu()
, is there a way to dynamically update the menu? -
Hi and welcome to devnet,
Call the same method with a nullptr.
Sure you can change the menu. It's not fixed in stone.
-
@DeeDee14 Then you're doing something wrong. It works as expected, also the code explicitly allows this.
QPushButton pb; QMenu *myMenu = new QMenu; pb.setMenu(myMenu); QTimer::singleShot(2000, &pb, [&]() { pb.setMenu(nullptr); }); pb.show();
-
This post is deleted!
-