How to unset QMenu from QPushButton?
-
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.
-
Hi and welcome to devnet,
Call the same method with a nullptr.
Sure you can change the menu. It's not fixed in stone.
-
@SGaist I did try - it didn't work. It still shows the previous menu with those menu items/actions. :(
@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();
-
@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! -