PDA

View Full Version : button question



aegis
29th March 2007, 23:57
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

zeki709
30th March 2007, 00:10
You can use QContextMenuEvent.

high_flyer
30th March 2007, 09:47
is there any widget that will do this, off the shelf?

Yes - QPushButton :)
Connect the clicked() signal to a slot, in that slot emit a QContextMenuEvent.

jpn
30th March 2007, 09:58
How about using QToolButton? It supports a menu with three different popup styles, out of the box.

aegis
30th March 2007, 20:04
Yes - QPushButton :)
Connect the clicked() signal to a slot, in that slot emit a QContextMenuEvent.

any guide on how to do this?

aegis
30th March 2007, 20:05
also any guide on how to do this?

high_flyer
30th March 2007, 21:43
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

aegis
31st March 2007, 19:20
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}





oneAction= new QAction("do something!!", this);
connect(oneAction, SIGNAL(triggered()), this, SLOT(action()));
processMenu->addAction(oneAction);
menuButton->setMenu(&processMenu);


what is the difference? between these 2 ways?

wysota
31st March 2007, 19:33
That's exactly the same what Jpn suggested.

high_flyer
1st April 2007, 09:06
what is the difference? between these 2 ways?
The method from the book that Jpn suggested uses QActions and signals.
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.