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?
Forum Updated to NodeBB v4.3 + New Features

Show text on QToolButton instead of icon?

Scheduled Pinned Locked Moved Solved General and Desktop
qtoolbuttonqaction
9 Posts 3 Posters 2.4k Views 2 Watching
  • 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 4 Aug 2020, 23:40 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Aug 2020, 19:42 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 J 2 Replies Last reply 5 Aug 2020, 21:38
      2
      • S SGaist
        5 Aug 2020, 19:42

        Hi,

        You can use QToolButton::setToolButtonStyle.

        L Offline
        L Offline
        lansing
        wrote on 5 Aug 2020, 21:38 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 Aug 2020, 21:44 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 5 Aug 2020, 21:57
          1
          • S SGaist
            5 Aug 2020, 21:44

            You can use the QAction::iconText property.

            L Offline
            L Offline
            lansing
            wrote on 5 Aug 2020, 21:57 last edited by
            #5

            @SGaist

            Thank you it works.

            1 Reply Last reply
            0
            • S SGaist
              5 Aug 2020, 19:42

              Hi,

              You can use QToolButton::setToolButtonStyle.

              J Offline
              J Offline
              JoeCFD
              wrote on 24 Feb 2023, 22:17 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.

              S 1 Reply Last reply 25 Feb 2023, 20:33
              0
              • J JoeCFD
                24 Feb 2023, 22:17

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

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 25 Feb 2023, 20:33 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

                J 1 Reply Last reply 26 Feb 2023, 04:02
                0
                • S SGaist
                  25 Feb 2023, 20:33

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

                  J Offline
                  J Offline
                  JoeCFD
                  wrote on 26 Feb 2023, 04:02 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.

                  S 1 Reply Last reply 26 Feb 2023, 20:16
                  0
                  • J JoeCFD
                    26 Feb 2023, 04:02

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

                    S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 26 Feb 2023, 20:16 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