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

How to get access to QToolButton?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 4.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.
  • HarbH Offline
    HarbH Offline
    Harb
    wrote on last edited by
    #1

    Hi! For example I have a window with tool bar. I have created this windows in Qt Designer. Then I programmaticaly add actions to the tool bar, using ui->toolBar->addAction() function. Calling this function add toolbutton to the toolBar. How can I get access to that toolbutton object? For example I want to change some of toolbutton properties (make it autorise, enable pupupMode, etc.)

    RatzzR 1 Reply Last reply
    0
    • HarbH Harb

      Hi! For example I have a window with tool bar. I have created this windows in Qt Designer. Then I programmaticaly add actions to the tool bar, using ui->toolBar->addAction() function. Calling this function add toolbutton to the toolBar. How can I get access to that toolbutton object? For example I want to change some of toolbutton properties (make it autorise, enable pupupMode, etc.)

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @Harb
      you can try this
      ui->toolButton->setPopupMode(mode)
      ui->toolButton->setAutoRaise(true);

      --Alles ist gut.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jakob
        wrote on last edited by
        #3

        @Harb This depends a bit on which overload of addAction you use. When you use the QAction* addAction(const QString&) overload, as the function signature tells you, you get back the new QAction object, which you may use to access the specifics.

        However, when using addAction(), you don't add a QToolButton AFAIK. If you specifically want to have a QToolButton on your toolbar, you have to create one yourself, then add it to the toolbar using QAction* addWidget(QWidget*), in other words, something along the lines of this:

        QToolButton* tool = new QToolButton;
        ui->toolBar->AddWidget(tool);
        
        HarbH 1 Reply Last reply
        1
        • J Jakob

          @Harb This depends a bit on which overload of addAction you use. When you use the QAction* addAction(const QString&) overload, as the function signature tells you, you get back the new QAction object, which you may use to access the specifics.

          However, when using addAction(), you don't add a QToolButton AFAIK. If you specifically want to have a QToolButton on your toolbar, you have to create one yourself, then add it to the toolbar using QAction* addWidget(QWidget*), in other words, something along the lines of this:

          QToolButton* tool = new QToolButton;
          ui->toolBar->AddWidget(tool);
          
          HarbH Offline
          HarbH Offline
          Harb
          wrote on last edited by
          #4

          @Jakob
          from documentation:
          Tool buttons are normally created when new QAction instances are created with QToolBar::addAction() or existing actions are added to a toolbar with QToolBar::addAction(). It is also possible to construct tool buttons in the same way as any other widget, and arrange them alongside other widgets in layouts.

          Apparently addAction() create QToolButton object. The question is about getting pointer to this tool button.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            delt
            wrote on last edited by
            #5

            You can use something like:

            mytoolbutton = mytoolbar->widgetForAction (myaction);
            
            1 Reply Last reply
            1

            • Login

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