Potch
3rd July 2008, 15:33
Hello,
I have several QPushButtons on which I added the same contextual menu this way :
setContextMenuPolicy(Qt::ActionsContextMenu);
QAction* MyAction = new QAction("DoThis");
connect(MyAction, SIGNAL(triggered()), this, SLOT(MySlot()));
addAction(MyAction);
For every button, there's a contextual menu with the same action. This action is connected to one slot. This slot has to behave differently regarding to the sender.
So far I can easily recover the occurrence of the button the user clicked on using :
QPushButton* PB = qobject_cast<QPushButton*>( sender() );
PB->etc...
My problem is to recover the occurence of the button on which the user used the contextual menu. For QAction inherits QObject, I tried
QAction* TheAction= qobject_cast<QAction*>( sender() );
But then how to make the link between the QAction and the QPushButton ?
I associated the same action to all the buttons. Is it a problem ?
Please feel free to ask me if I didn't made myself clear.
Thanks in advance.
I have several QPushButtons on which I added the same contextual menu this way :
setContextMenuPolicy(Qt::ActionsContextMenu);
QAction* MyAction = new QAction("DoThis");
connect(MyAction, SIGNAL(triggered()), this, SLOT(MySlot()));
addAction(MyAction);
For every button, there's a contextual menu with the same action. This action is connected to one slot. This slot has to behave differently regarding to the sender.
So far I can easily recover the occurrence of the button the user clicked on using :
QPushButton* PB = qobject_cast<QPushButton*>( sender() );
PB->etc...
My problem is to recover the occurence of the button on which the user used the contextual menu. For QAction inherits QObject, I tried
QAction* TheAction= qobject_cast<QAction*>( sender() );
But then how to make the link between the QAction and the QPushButton ?
I associated the same action to all the buttons. Is it a problem ?
Please feel free to ask me if I didn't made myself clear.
Thanks in advance.