Combobox with checkable items issues
I need to implement QComboBox with checkable items. As I understand, this can be done by using QStandardItemModel and QStandarItem with corresponding flags set.
I successfully implemented this, but my code works only in some systems/ desktop environments. For example, it works under WIndows XP/7 and 10, as well as in KDE. But it does not work in Gnome and some window managers (I tested with OpenBox). Is this Qt bug or something wrong with my code? Should I submit a ticket?
Here is small example to reproduce
from PyQt4.QtGui import * from PyQt4.QtCore import * data = ['item 1', 'item 2', 'item 3'] class Example(QComboBox): def __init__(self): super(Example, self).__init__() self.model = QStandardItemModel(len(data), 1) for i, f in enumerate(data): item = QStandardItem(f) item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setData(Qt.Unchecked, Qt.CheckStateRole) self.model.setItem(i, 0, item) self.setModel(self.model) self.show() def main(): app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) if __name__ == '__main__': main()
P.S. I searched in forum and found similar issue in this old thread https://forum.qt.io/topic/11769/pyqt-combobox-with-checkable-items-no-external-libs
It wouldn't surprise me that this design is running against the Human Interfaces Guidelines of these window managers.
Out of curiosity, what do you need such a special combo box for ?
I need special combobox because there are variable list of options and user should be able to select multiple options. Also as this list can be relatively long I don't want to use listbox and make my dialog bigger.
I would use list-box. It does not have to be as big as the number of the entries (a scrollbar will be shown if it is smaller). It is really unusual and confusing to have check-boxes inside a combo-box.
@jsulm yes, I know that ListBox have scrollbars. But behavior I described is a bug, isn't it?