Search code examples
c++qtcomboboxqcombobox

Qt : How to get QComboBox item text at an arbitrary index (not the currently selected item)


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)?


Solution

  • 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