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. Show text on QToolButton instead of icon?
QtWS25 Last Chance

Show text on QToolButton instead of icon?

Scheduled Pinned Locked Moved Solved General and Desktop
qtoolbuttonqaction
9 Posts 3 Posters 2.2k 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.
  • L Offline
    L Offline
    lansing
    wrote on last edited by
    #1

    I have a QAction with checkable, icon and text all set. And then I assigned it to the menu and a QToolButton . It looks fine on the menu with icon and text showing side by side. However for the QToolButton, I want to set a shorter text and show it instead of the icon and text from the QAction.

    pMenu->addAction(m_pActionShowMyDialog);
        
    m_ui->myDialogButton->setDefaultAction(m_pActionShowMyDialog);
    m_ui->myDialogButton->setText("MD");
    

    I tried to setText on the button after setting the QAction but it still shows the icon.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can use QToolButton::setToolButtonStyle.

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

      L JoeCFDJ 2 Replies Last reply
      2
      • SGaistS SGaist

        Hi,

        You can use QToolButton::setToolButtonStyle.

        L Offline
        L Offline
        lansing
        wrote on last edited by
        #3

        @SGaist

        Hi, how do I set it to a different text than the one from the action? The text from the action is too long for the button and I want to set it to a shorter one.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can use the QAction::iconText property.

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

          L 1 Reply Last reply
          1
          • SGaistS SGaist

            You can use the QAction::iconText property.

            L Offline
            L Offline
            lansing
            wrote on last edited by
            #5

            @SGaist

            Thank you it works.

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              You can use QToolButton::setToolButtonStyle.

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by JoeCFD
              #6

              @SGaist This does not work anymore with Qt 5.15.3 on Ubuntu 22.04. My tool button works fine on Ubuntu 18.04.

              SGaistS 1 Reply Last reply
              0
              • JoeCFDJ JoeCFD

                @SGaist This does not work anymore with Qt 5.15.3 on Ubuntu 22.04. My tool button works fine on Ubuntu 18.04.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @JoeCFD what if you use the Qt version from the distribution ?

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

                JoeCFDJ 1 Reply Last reply
                0
                • SGaistS SGaist

                  @JoeCFD what if you use the Qt version from the distribution ?

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by JoeCFD
                  #8

                  @SGaist Qt 5.15.3 is the one in the distribution of Ubuntu 22.04 and QToolButton with flag Qt::ToolButtonTextOnly still shows the icon. I solved the issue by setting an empty icon for this flag. Before, I did not need to.

                  SGaistS 1 Reply Last reply
                  0
                  • JoeCFDJ JoeCFD

                    @SGaist Qt 5.15.3 is the one in the distribution of Ubuntu 22.04 and QToolButton with flag Qt::ToolButtonTextOnly still shows the icon. I solved the issue by setting an empty icon for this flag. Before, I did not need to.

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @JoeCFD from the looks of it, it could be an Ubuntu specific bug.

                    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

                    • Login

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