Guest User

QListWidgetItem checkbox issue

a guest
Sep 21st, 2026
7
0
126 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | Source Code | 0 0
  1. import sys
  2.  
  3. from PySide6.QtWidgets import QStyleFactory
  4.  
  5. from PySide6.QtWidgets import QApplication, QMainWindow, QListWidget, QListWidgetItem, QVBoxLayout, QWidget
  6. from PySide6.QtCore import Qt
  7.  
  8.  
  9. class MainWindow(QMainWindow):
  10.     def __init__(self):
  11.         super().__init__()
  12.         self.setWindowTitle("All rows should be checkable, only the first one is.")
  13.         layout=QVBoxLayout()
  14.         checklist=QListWidget()
  15.         # Uncommentting the following line fixes the issue (with a different style)
  16.         #checklist.setStyle(QStyleFactory.create("Fusion"))
  17.         checklist.clear()
  18.         # Add 3 checkable rows.
  19.         for name in ["foo", "bar", "baz"]:
  20.             item=QListWidgetItem(name)
  21.             item.setFlags(Qt.ItemIsUserTristate|Qt.ItemIsUserCheckable|Qt.ItemIsEnabled|item.flags())
  22.             item.setCheckState(Qt.Checked)
  23.             checklist.addItem(item)
  24.         layout.addWidget(checklist)
  25.         central=QWidget()
  26.         central.setLayout(layout)
  27.         self.setCentralWidget(central)
  28.  
  29.  
  30. app=QApplication(sys.argv)
  31. win=MainWindow()
  32. win.show()
  33. app.exec()
  34.  
Tags: python qt PySide6
Advertisement
Add Comment
Please, Sign In to add comment