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. Update QAction and QToolButton
Forum Update on Monday, May 27th 2025

Update QAction and QToolButton

Scheduled Pinned Locked Moved Solved General and Desktop
menutoolbarqtoolbarqtoolbuttonwidgets
3 Posts 2 Posters 1.1k 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.
  • M Offline
    M Offline
    Maluna34
    wrote on 1 Jun 2022, 17:58 last edited by Maluna34 6 Jan 2022, 17:59
    #1

    Hello !

    I have in my QMenu an action, and a tool button in my QToolBar linked to this action.
    But I wanted the button in the toolbar to have a shorter text than the action in the menu:

    m_runTestsAction = testsMenu->addAction(runIcon, tr("Run tests"));
    m_runTestsAction->setEnabled(false);
    
    m_runTestsButton = new QToolButton;
    m_runTestsButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    m_runTestsButton->setDefaultAction(menuBar->getRunTestsAction());
    m_runTestsButton->setText(tr("Run"));
    

    Problem: each time I update the enable state of the action (to update both menu and toolbar), it puts back the full text under the button Run tests.

    Is it possible to update a field in the action and trigger only the same change on the tool button?

    Thanks!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 1 Jun 2022, 18:52 last edited by
      #2

      The button's icon text is taken from QActions iconText() property. So set the iconText to 'Run'.

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

      M 1 Reply Last reply 1 Jun 2022, 20:23
      3
      • C Christian Ehrlicher
        1 Jun 2022, 18:52

        The button's icon text is taken from QActions iconText() property. So set the iconText to 'Run'.

        M Offline
        M Offline
        Maluna34
        wrote on 1 Jun 2022, 20:23 last edited by
        #3

        @Christian-Ehrlicher Thanks a lot, it is exactly what I was missing!

        1 Reply Last reply
        0

        1/3

        1 Jun 2022, 17:58

        • Login

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