Get more selectable options by clicking on a option
-
Hello i have a action called "More" in my Application. So if im going to click on that action i want to open a list with more options to select. So something like that:
Do you know what the syntax is i need or which methods ?
Regards -
@developer_61 Sounds like menu. See QMenu if you're using widgets.
-
@jsulm yeah but im using a toolbar. So it is possible to click on a element on the toolbar to get the menu?
-
-
@jsulm i think wouldn't work. i mean i have a QTtoolbar with QTactions in it.
So i need a method for QTactions. -
@developer_61
You can add a QToolButton to a QToolBar byQAction *QToolBar::addWidget(QWidget *widget)
.
That's very common.
I happen to have some sample code.QMenu* menu = new QMenu(this); QAction* subAct1 = new QAction(QStringLiteral("SubAction1")); QAction* subAct2 = new QAction(QStringLiteral("SubAction2")); menu->addAction(subAct1); menu->addAction(subAct2); QToolButton* toolButton = new QToolButton(ui->toolBar); toolButton->setText(QStringLiteral("More")); toolButton->setMenu(menu); toolButton->setPopupMode(QToolButton::InstantPopup); ui->toolBar->addWidget(toolButton);
-
@Bonnie thank you very much. And it is possible to do that without coding? so directly in the qt designer?
-
@developer_61
Unfortunately I think that's not possible. -
@Bonnie yeah cause i try to add a tool button to the tool bar but thats not possible. Only Qactions is allowed.
But anyway thank you very much ! -
another question ... @Bonnie
is it possible to hide that arrow next to the text
-
@developer_61
That's a frequently asked question :)
The easiest way is to use stylesheet.toolButton->setStyleSheet("QToolButton::menu-indicator { image: none; }");
-
@Bonnie thank you !!!
One last question:
is it possible to make an icon instad of more ? -
@developer_61
Of course!
Just usetoolButton->setIcon(...)
(maybe also withtoolButton->setIconSize(...)
) instead oftoolButton->setText(...)
.
It has the same functions as a QToolButton in the designer. -
@Bonnie thank you !!