How to get access to QToolButton?
-
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.)
-
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.)
-
@Harb This depends a bit on which overload of
addActionyou use. When you use theQAction* addAction(const QString&)overload, as the function signature tells you, you get back the newQActionobject, which you may use to access the specifics.However, when using
addAction(), you don't add aQToolButtonAFAIK. If you specifically want to have aQToolButtonon your toolbar, you have to create one yourself, then add it to the toolbar usingQAction* addWidget(QWidget*), in other words, something along the lines of this:QToolButton* tool = new QToolButton; ui->toolBar->AddWidget(tool); -
@Harb This depends a bit on which overload of
addActionyou use. When you use theQAction* addAction(const QString&)overload, as the function signature tells you, you get back the newQActionobject, which you may use to access the specifics.However, when using
addAction(), you don't add aQToolButtonAFAIK. If you specifically want to have aQToolButtonon your toolbar, you have to create one yourself, then add it to the toolbar usingQAction* addWidget(QWidget*), in other words, something along the lines of this:QToolButton* tool = new QToolButton; ui->toolBar->AddWidget(tool);@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.