I want to display a QListView where each item is a checkbox with some label. The checkboxes should be visible at all times. One way I can think of is using a custom delegate and QAbstractListModel. Are there simpler ways? Can you provide the simplest snippet that does this?
Thanks in advance
If you are writing your own model, just include the
Qt.ItemIsUserCheckableflag in the return value from the
flags()method, and ensure that you returna valid value for the
Qt.CheckStateRolefrom thedata()method.If you use the
QStandardItemModelclass, include theQt.ItemIsUserCheckableflag in those you pass to each item’s
setFlags()method, and set the checkstate for the
Qt.CheckStateRolewith itssetData()method.In an interactive Python session, type the following: