Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions
Associating one menu with two QToolButton
Ayush Gupta last edited by
I have some menu with some QActions like
QMenu test = new QMenu;
QAction action1 = new QAction("test1",this);
QAction action2 = new QAction("test2",this);
Now adding QAction to menu
Now to QPushButton
QToolButton *button1 = new QToolButton(this);
QToolButton *button2 = new QToolButton(this);
attaching menu to QToolButton
Now I need to connect the signal to QAction test1,test2.
And do something according to the type of QPushButton. But how can I get to know the QPushButton type when I clicked on QAction since common menu is associated with two QToolButton.
Is this possible?
NotYourFan last edited by NotYourFan
you can check the Signals form QAction here: QAction - Signals.
Why you use QAction and not QPushButton?
QPushButton have a signal "clicked" ...
But how can I get to know the QPushButton type when I clicked on QAction
I don't know what you mean with "type", but you can connect a lambda to the clicked() signal from the buttons and pass additional parameters to the lambda to differentiate the buttons.
umod.47 last edited by
You can call sender() inside a slot to determine calling object and just compare, which button caused the slot to execute.
@umod-47 you can, but you shouldn't, let me quote the documentation