I have QComboBox
and I set QStandardItemModel
because I need multi-select check-boxes in it.
Problem is that when I read text value and check state of items in comboBox, they disappear from combo.
This is how I set model to comboBox:
areas = ["Area one", "Area two", "Area three", "Area four"]
model = QtGui.QStandardItemModel(4, 1)# 4 rows, 1 col
for i,area in enumerate(areas):
item = QtGui.QStandardItem(area)
item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
item.setData(QtCore.Qt.Unchecked, QtCore.Qt.CheckStateRole)
model.setItem(i, 0, item)
self.ui.comboBox.setModel(model)
This is how I read data from comboBox:
modelColumn = self.ui.comboBox.model().takeColumn(0)
for item in modelColumn:
print item.text(),"---", item.checkState()
Here is a screenshot before and after I read data from combo box:
...and result I get, as expected:
Area one --- 0
Area two --- 2
Area three --- 2
Area four --- 0
Also, is there simple way not to show "Area one" when comboBox is inactive (I want to see only arrow in right corner like on second picture) or to set other text to be shown, like "choose area"?