QToolButton* button = new QToolButton(this); // create new QToolButton widget button->setIcon(QIcon("path/to/icon.png")); // set the icon for the button
// assume we have a QToolBar called toolbar QAction* action = toolbar->addAction(QIcon("path/to/icon.png"), "Tooltip text"); QToolButton* button = qobject_castThis example adds a new action to a pre-existing QToolBar and sets the icon and tooltip text for the action. It then retrieves the QToolButton widget that corresponds to the action and sets its tool button style to "Qt::ToolButtonTextUnderIcon". The package library used in this example is QtWidgets.(toolbar->widgetForAction(action)); button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);