Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Unsolved How to replace the QAction of a QToolButton without enabling menu

    General and Desktop
    qaction qtoolbutton default action
    2
    4
    837
    Loading More Posts
    • 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.
    • A
      Arthur Araruna last edited by

      I have a QToolButton that I want to change behavior depending on user interaction. The behaviors are implemented as QActions, 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 the menu() 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) and setVisible(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 named add... or remove...?

      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        Just connect the action to another slot. Or do a switch in the slot.

        Qt has to stay free or it will die.

        A 1 Reply Last reply Reply Quote 2
        • A
          Arthur Araruna @Christian Ehrlicher last edited by Arthur Araruna

          @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.

          1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by

            You said you're using QActions - just reconnect them to other slots depending on your current state.

            Qt has to stay free or it will die.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post