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.)
you can try this
@Harb This depends a bit on which overload of
addActionyou use. When you use the
QAction* addAction(const QString&)overload, as the function signature tells you, you get back the new
QActionobject, which you may use to access the specifics.
However, when using
addAction(), you don't add a
QToolButtonAFAIK. If you specifically want to have a
QToolButtonon 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);
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.
You can use something like:
mytoolbutton = mytoolbar->widgetForAction (myaction);