How to do something while a QAction in the toolbar is kept pressed?
-
wrote on 1 Jun 2022, 03:12 last edited by
I want to show the user a custom menu that I made while the user presses a QAction button in the toolbar. As soon as the user releases this button, I want the menu to disappear. I am able to handle the menu part, but I am confused about how to manage the pressed and released aspect of the QAction, since QAction does not have these attributes.
Just to be clear, I want to do some action when the mouse click is down, and as soon as the mouse click is up, I want to stop that action.
Thanks.
-
Hi,
QToolButton already supports menus.
What do you want to achieve with your custom implementation ?
-
wrote on 2 Jun 2022, 02:56 last edited by
Hi,
Thanks for the answer. QToolButton supports menus, but the buttons I have in my toolbar are QAction not QToolButton. Can I add a QToolButton to the toolbar too?
If so, how? -
Hi,
Thanks for the answer. QToolButton supports menus, but the buttons I have in my toolbar are QAction not QToolButton. Can I add a QToolButton to the toolbar too?
If so, how?wrote on 2 Jun 2022, 03:15 last edited by@BigBen You can get the QToolButton associated with the QAction using
widgetForAction
from yourQToolBar
widgetPython
toolbar.widgetForAction(your_action)
Otherwise, you could try intercepting
mousePressEvent
andmouseReleaseEvent
. -
wrote on 2 Jun 2022, 06:36 last edited by
@BigBen Also check out
eventFilter
. Here's a link to the documentation.
5/5