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
For Gerrit Dashboard: PYSIDE-1930 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
414342,11 | pyside: Modify QAbstractListModel.data(..) to consider enums | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
416626,4 | pyside: Modify QAbstractListModel.data(..) to consider enums | 6.3 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
417246,8 | fix if else in qabstractitemmodel_data | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
418483,4 | Fix returning flags from QAbstractTableModel and other models | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
418669,2 | Fix returning flags from QAbstractTableModel and other models | 6.3 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
437295,6 | PySide6: Fix enum to QVariant conversion for the new enums | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
437387,2 | PySide6: Fix enum to QVariant conversion for the new enums | 6.3 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
480654,15 | Enum: Enable toInt for QVariant(PyEnum/SbkEnum) | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
484732,2 | Enum: Enable toInt for QVariant(PyEnum/SbkEnum) | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |