Question

I am using PyQt4 and Qt Designer. I have a QListWidget in which I populate after loading a file in my program.

I want to set it so that all items will be checkable, as opposed to just selectable. I have found online that this is a 'flag' of the QListWidget, however, in Qt Designer I can't see where to do this.

Is it possible?

Was it helpful?

Solution

You can do this by opening the edit list widget item tab , and look into the properties. and set the checkState property.

enter image description here

**UPDATE **

item = QtGui.QListWidgetItem()
item.setText(QtGui.QApplication.translate("Dialog", x, None,    QtGui.QApplication.UnicodeUTF8))
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
item.setCheckState(QtCore.Qt.Unchecked)
self.listWidget.addItem(item)

OTHER TIPS

The age-old question. There is an answer here, but I'll try to give some clarification: for several components there isn't enough to set item flag Qt::ItemIsUserCheckable, one needs to set item's check state for the checkbox to appear. Also, there is no widget flag to make all items checkable.

An excerpt from Qt documentation:

Note that checkable items need to be given both a suitable set of flags and an initial state, indicating whether the item is checked or not. This is handled automatically for model/view components, but needs to be explicitly set for instances of QListWidgetItem, QTableWidgetItem, and QTreeWidgetItem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top