QComboBox menu, set Option menu from Variable
Solved
General and Desktop
-
Hi, I have the next QComboBox menu:
QComboBox *Mode = new QComboBox(this); Mode->addItem(tr("Off")); Mode->addItem(tr("Manual")); Mode->addItem(tr("Automatic"));
The default option shown is "Off", the question is: How can I change the menu selected with a a varaible... it is possible?
my idea is : if(num == 3) Mode->setMenu(Automatic);
Any help will be wellcomed.
Thanks in advance
-
The easiest way will be to use
QComboBox::setCurrentIndex(int index)
.
Note that indexes start with 0, not with 1. So in your case "Automatic" would have index 2.QComboBox::setCurrentText()
was added somewhen after Qt 4.8 if that helps in your case.Hope that helps.
-
QComboBox::setCurrentIndex() should be what you are looking for. Unless I misunderstood you.