Hello,
I have several QPushButtons on which I added the same contextual menu this way :
setContextMenuPolicy(Qt::ActionsContextMenu);
connect(MyAction, SIGNAL(triggered()), this, SLOT(MySlot()));
addAction(MyAction);
setContextMenuPolicy(Qt::ActionsContextMenu);
QAction* MyAction = new QAction("DoThis");
connect(MyAction, SIGNAL(triggered()), this, SLOT(MySlot()));
addAction(MyAction);
To copy to clipboard, switch view to plain text mode
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...
QPushButton* PB = qobject_cast<QPushButton*>( sender() );
PB->etc...
To copy to clipboard, switch view to plain text mode
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
() );
QAction* TheAction= qobject_cast<QAction*>( sender() );
To copy to clipboard, switch view to plain text mode
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.
Bookmarks