qtqcombobox

How to show an item with a given index number in QComboBox?


I have added some items in a QComboBox and now I am trying to show an item on the QComboBox with given index.

For example:

In my QComboBox, I have three items; firstItem, secondItem, thirdItem, when I get an index number two, I want to see secondItem shown on the QComboBox.


Solution

  • You have to set the current index QComboBox::setCurrentIndex.

    ui->combo->setCurrentIndex(2);