How to replace the QAction of a QToolButton without enabling menu
-
I have a
QToolButton
that I want to change behavior depending on user interaction. The behaviors are implemented asQAction
s, that I want to swap with the current one on the button.The problem is that everytime I call
QToolButton::setDefaultAction
, the previous action gets replaced but added as a menu action of the button, making the button paint that little arrow. This is not what I wanted. I just wanted the new action to be the only available action the button had.I tried calling
clear()
on the button's menu (obtained from themenu()
method), but as it turns out, even though there are at least two actions associated with the button, no menu gets returned.Even if I call the inactive actions'
setEnabled(false)
andsetVisible(false)
, I still end up with the little arrow and the ability to expand the button's menu.What's happening? Is there any way I can achieve what I want? Will I need to have one
QToolButton
for each action and keep swapping them instead of the actions?Why is this the intended behavior, having a method named like
set
and none namedadd...
orremove...
? -
Just connect the action to another slot. Or do a switch in the slot.
-
@Christian-Ehrlicher said in How to replace the QAction of a QToolButton without enabling menu:
Just connect the action to another slot. Or do a switch in the slot.
I'm sorry, what slot? I didn't know
QToolButtons
had a slot related to actions...Thank you.
-
You said you're using QActions - just reconnect them to other slots depending on your current state.