I am trying to make a QComboBox
with checkable items. I created a custom Model, which my QComboBox
object uses (via the setModel()
method).
I tried using the solution presented in this question : https://stackoverflow.com/a/8423904
Here is my custom model :
class FilterModel(QStandardItemModel):
def __init__(self, filter_list, parent=None):
super(FilterModel, self).__init__(parent)
for index, filter in enumerate(filter_list):
item = QStandardItem(filter)
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
item.setData(Qt.Unchecked, Qt.CheckStateRole)
self.setItem(index, 0, item)
I pass the items as a list in the constructor when I instantiate my model.
However, my items are nor selectable, nor checkable (the checkbox isn't even displayed).