Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1930

REG ->6.2.4: Cannot return Qt.CheckState enum values from QAbstractItemModel::flags()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • None
    • 6.3
    • PySide
    • None
    • All
    • 20eb4f94c6 (pyside/pyside-setup/dev) 20eb4f94c6 (pyside/tqtc-pyside-setup/dev) 57f8beca8f (pyside/pyside-setup/6.3) 57f8beca8f (pyside/pyside-setup/wip/6.3_pypy) 57f8beca8f (pyside/tqtc-pyside-setup/6.3) 57f8beca8f (pyside/tqtc-pyside-setup/wip/6.3_pypy)

    Description

      With PySide6.3 and the following code, I cannot check or display checked state from a model.
      It was working with Pyside 6.2.

      
      from PySide6.QtWidgets import *
      from PySide6.QtCore import *
      from PySide6.QtGui import *
      import sys
      import typing
      
      
      class ChoiceModel(QAbstractListModel):
          def __init__(self, data: typing.List[dict]) -> None:
              super().__init__()
              self._data = data
      
          def rowCount(self, parent: QModelIndex = QModelIndex()) -> int:
              if parent == QModelIndex():
                  return len(self._data)
              return 0
      
          def data(self, index: QModelIndex, role: int = Qt.DisplayRole) -> typing.Any:
      
              if not index.isValid():
                  return
      
              if role == Qt.DisplayRole:
                  return self._data[index.row()]["name"]
      
              if role == Qt.CheckStateRole:
                  return Qt.Checked if self._data[index.row()]["checked"] else Qt.Unchecked
      
          def setData(
              self, index: QModelIndex, value: typing.Any, role: int = Qt.EditRole
          ) -> bool:
      
              if role != Qt.CheckStateRole:
                  return False
              if index.column() > 0:
                  return False
              self._data[index.row()]["checked"] = True if value == Qt.Checked else False
              self.dataChanged.emit(index, index, [role])
              return True
      
          def flags(self, index: QModelIndex) -> Qt.ItemFlags:
              return super().flags(index) | Qt.ItemIsUserCheckable | Qt.ItemIsEditable
      
          def checked_items(self):
              return [it["name"] for it in self._data if it["checked"]]
      
      
      if __name__ == "__main__":
      
          app = QApplication(sys.argv)
      
          view = QListView()
          model = ChoiceModel(
              [{"name": "test", "checked": True}, {"name": "test", "checked": True}]
          )
          view.setModel(model)
      
          view.show()
      
          app.exec()
      

      Attachments

        1. pyside1930_pyqt.py
          2 kB
          Christian Tismer
        2. pyside1930.py
          2 kB
          Christian Tismer

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              ctismer Christian Tismer
              sschutz sacha schutz
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: