Long story short, I use a QListWidget as a checklist. I would like to set a custom style for some items which are not checkable and rather act as text headers. I found this solution on Stack Overflow (last answer) for QTreeWidget, but I couldn't get it to work with QListWidget. Example;
![[Image: Deepin-Screenshot-spacefm-20201128184259.png]](https://i.postimg.cc/wv6MPYLB/Deepin-Screenshot-spacefm-20201128184259.png)
If that is not possible, does anyone know how to do the QStyledItemDelegate thing in PyQt?
The app use CSS quite heavily so I have to stick with that. Thanks.
#!/usr/bin/python3 from PyQt5 import QtWidgets class Main(QtWidgets.QWidget): def __init__(self, parent): super().__init__() self.listWidget = QtWidgets.QListWidget() self.layout = QtWidgets.QVBoxLayout() self.layout.addWidget(self.listWidget) self.setLayout(self.layout) self.show() item1 = QtWidgets.QListWidgetItem("Regular item") item2 = QtWidgets.QListWidgetItem("Label item") label = QtWidgets.QLabel() self.listWidget.addItem(item1) self.listWidget.addItem(item2) self.listWidget.setItemWidget(item2, label) style = """ QListWidget::item { color: blue; } QLabel { color: red; } """ parent.setStyleSheet(style) if __name__ == '__main__': app = QtWidgets.QApplication([]) gui = Main(app) app.exec()
![[Image: Deepin-Screenshot-spacefm-20201128184259.png]](https://i.postimg.cc/wv6MPYLB/Deepin-Screenshot-spacefm-20201128184259.png)
If that is not possible, does anyone know how to do the QStyledItemDelegate thing in PyQt?
The app use CSS quite heavily so I have to stick with that. Thanks.