hi, i want to create a button that when pressed it will display a context menu...
is there any widget that will do this, off the shelf?
is it easy to implement it by myself?
thanks for your time,
NA
Printable View
hi, i want to create a button that when pressed it will display a context menu...
is there any widget that will do this, off the shelf?
is it easy to implement it by myself?
thanks for your time,
NA
You can use QContextMenuEvent.
Yes - QPushButton :)Quote:
is there any widget that will do this, off the shelf?
Connect the clicked() signal to a slot, in that slot emit a QContextMenuEvent.
How about using QToolButton? It supports a menu with three different popup styles, out of the box.
also any guide on how to do this?
I gave you the 'guide', what more do you need?
1. create a slot
2. connect the clicked() signal to that slot
3. in the slot emit the event
in the book c++ gui programming with qt4 i found another way{create an action, populate a menu, connect the menu with button}
Code:
connect(oneAction, SIGNAL(triggered()), this, SLOT(action())); processMenu->addAction(oneAction); menuButton->setMenu(&processMenu);
what is the difference? between these 2 ways?
That's exactly the same what Jpn suggested.
The method from the book that Jpn suggested uses QActions and signals.Quote:
what is the difference? between these 2 ways?
I find it also better, so use it.
The other method is using an event, which probably is what happens with the signal method behind the scenes.