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 replace the QAction of a QToolButton without enabling menu
QtWS25 Last Chance

How to replace the QAction of a QToolButton without enabling menu

Scheduled Pinned Locked Moved Unsolved General and Desktop
qactionqtoolbuttondefault action
4 Posts 2 Posters 1.5k 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.
  • A Offline
    A Offline
    Arthur Araruna
    wrote on last edited by
    #1

    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
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

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

        A Offline
        A Offline
        Arthur Araruna
        wrote on last edited by Arthur Araruna
        #3

        @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
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0

          • Login

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