2

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.

mehmetozer
  • 848
  • 6
  • 14
  • 30

2 Answers2

2

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

ui->combo->setCurrentIndex(2);
pnezis
  • 12,023
  • 2
  • 38
  • 38
0

You can set QComboBox to display any item as you choose based on index using setCurrentIndex() method. As an example:

....     
artistView = new QComboBox; 
...
index = <some input>;
...
artistView->setCurrentIndex(index);///sets the index
Karlson
  • 2,958
  • 1
  • 21
  • 48