As in Qt to make a combobox similar to the settings (⋮) in Android
-
Hi
Im not sure how that looks or works..
What is the difference from a normal combobox ? -
Hi
https://doc.qt.io/qt-5/qmenu.html#addAction
returns the action so you can connect to its triggered() signal -
hi
and what does connect return ?
If you check the docs, you will see that it has a parameter.
so i think you connect is invalid.connect(menu, SIGNAL(triggered(bool)), this, SLOT(testSlot(bool)));
and make sure the testSlot do in fact take a bool. ( by adding it ) -
Ant this not works:
QMenu* menu = new QMenu(this); QAction *action0 = new QAction(this); QAction *action1 = new QAction(this); action0->setText("Настройки"); action1->setText("О программе"); menu->addAction(action0); menu->addAction(action1); //menu->addAction(tr("Настройки")); //menu->addAction(tr("О программе")); ui->optionButton->setMenu(menu); connect(menu, SIGNAL(triggered(action0)), this, SLOT(testSlot()));
-
@Mikeeeeee said in As in Qt to make a combobox similar to the settings (⋮) in Android:
Ant this not works:
QMenu* menu = new QMenu(this); QAction *action0 = new QAction(this); QAction *action1 = new QAction(this); action0->setText("Настройки"); action1->setText("О программе"); menu->addAction(action0); menu->addAction(action1); //menu->addAction(tr("Настройки")); //menu->addAction(tr("О программе")); ui->optionButton->setMenu(menu); connect(menu, SIGNAL(triggered(action0)), this, SLOT(testSlot()));
You should write the prototype of the signal.
void QMenu::triggered(QAction *action)
void QAction::triggered(bool checked = false)
So, if you are trying to use these signal then you could follow the below examples
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(testSlot())); // OR connect(action0, SIGNAL(triggered(bool)), this, SLOT(testSlot())); connect(action1, SIGNAL(triggered(bool)), this, SLOT(testSlot()));
Note:
QMenu::triggered
pass the triggered action as parameter whileQAction::triggered
is useful to connect a specific action to specific slots. -
@Mikeeeeee
Use a simple stylesheet on your buttonui->optionButton->setStyleSheet("QAbstractButton::menu-indicator{width:0}");