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

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

        M Offline
        M Offline
        Maluna34
        wrote on last edited by
        #3

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

        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