4

Extracting text of the selected QComboBox item is well known, but how do I get the text in a QComboBox for an arbitrary index item (not necessarily the one selected)?

daj
  • 6,962
  • 9
  • 45
  • 79

1 Answers1

4

Use itemText() method to do this. Just set needed index.

As Marek R pointed, you can get model and get data from this model, but it will be helpful for you when you want to get something more than text( for example get image with Qt::DecorationRole or font with Qt::FontRole)

http://qt-project.org/doc/qt-4.8/qcombobox.html#itemText

http://qt-project.org/doc/qt-4.8/qcombobox.html#model

Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • 1
    [model](http://qt-project.org/doc/qt-4.8/qcombobox.html#model) gives even more control over the combobox items. – Marek R Nov 18 '14 at 09:06
  • @MarekR yes you are right, I didn't add this to answer earlier becuase I thought that OP needs only text. But it is good point, so I added it, thank you for pointing. – Jablonski Nov 18 '14 at 13:55