Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to do something while a QAction in the toolbar is kept pressed?

How to do something while a QAction in the toolbar is kept pressed?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qactionpressedreleasedtoolbar
5 Posts 3 Posters 713 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BigBen
    wrote on 1 Jun 2022, 03:12 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 1 Jun 2022, 19:24 last edited by
      #2

      Hi,

      QToolButton already supports menus.

      What do you want to achieve with your custom implementation ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BigBen
        wrote on 2 Jun 2022, 02:56 last edited by
        #3

        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?

        A 1 Reply Last reply 2 Jun 2022, 03:15
        0
        • B BigBen
          2 Jun 2022, 02:56

          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?

          A Offline
          A Offline
          adamhendry
          wrote on 2 Jun 2022, 03:15 last edited by
          #4

          @BigBen You can get the QToolButton associated with the QAction using widgetForAction from your QToolBar widget

          Python

          toolbar.widgetForAction(your_action)
          

          Otherwise, you could try intercepting mousePressEvent and mouseReleaseEvent.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            adamhendry
            wrote on 2 Jun 2022, 06:36 last edited by
            #5

            @BigBen Also check out eventFilter. Here's a link to the documentation.

            1 Reply Last reply
            0

            4/5

            2 Jun 2022, 03:15

            • Login

            • Login or register to search.
            4 out of 5
            • First post
              4/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved