Details
-
Bug
-
Resolution: Done
-
P4: Low
-
None
-
6.3
-
None
-
-
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
Issue Links
- is duplicated by
-
PYSIDE-1954 Qt.CheckStateRole not displayed in QAbstractItemView
- Closed
-
PYSIDE-2012 QAbstractTableModel Alignment flags Has a Wrong Behavior on it's QTableView
- Closed
-
PYSIDE-1993 Qt.Checked state isn't rendered correctly by Qt.CheckStateRole in QTableView
- Closed
-
PYSIDE-168 QtCore.Alignment objects are not correctly interpreted when returned from item.data()
- Closed
- relates to
-
PYSIDE-2209 调用QTableWidgetItem.setTextAlignment设置字体居中,导致内存泄漏
- Closed
-
PYSIDE-1974 Regression: Usage of PySide6 enums via QVariant broken
- Closed
-
PYSIDE-2840 Enum properties unsupported in Qt Designer custom widgets
- Closed
-
PYSIDE-2339 Enums returned from QAIM::data() get casted to ints for StyledItemDelegate.displayText()
- Closed
- resulted from
-
PYSIDE-1798 Cannot store enum Qt.PenStyle object as user data of QComboBox item (QVariant)
- Closed