I have a QListWidget where I want to add a bunch of items with a custom widget:
listWidget = QListWidget()
item = QListWidgetItem()
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Unchecked)
listWidget.addItem(item)
widget = MyLabelAndPushButton()
item.setSizeHint(widget.sizeHint())
listWidget.setItemWidget(item, widget)
As the name suggests MyLabelAndPushButton is just a widget containing a QLabel and a QPushButton in a layout. The problem is that I can not use the checkbox that appears in the listwidget next to the widget. It looks completely normal, but nothing happens when I click on it. If I remove the line with setItemWidget it works correctly. What am I doing wrong?
edit:
Reported bug at bugreports.qt.io/browse/QTBUG-16386 but got the reply "API is not designed for what you intend to do" and "In case if you want to display custom widget, use QListView and subclass QItemDelegate." So apparently it's not a bug, just something the API can't handle.