How to use Model for QCombobox

ibrahimyilmaz picture ibrahimyilmaz · Aug 27, 2010 · Viewed 14.8k times · Source

I want to use QCombobox as a the Combobox of Swing in Java. So i need to use Model for holding my object. How can i hold my object in QCombobox. (I think that I should hold data in Model because QCombobox was designed according to MVC Pattern ... ) Any help will be appreciated.

Answer

Jérôme picture Jérôme · Aug 27, 2010

Depending on what you want to display with your QComboBox, you'll need to write your own model, inheriting QAbstractListModel, reimplementing rowCount()and data().

Then, use QComboBox::setModel() to make the QComboBox display it.

If you just want to display strings, you can use a QStringListModel, provided with Qt.