Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
6.5.0, 6.4.3
-
None
Description
Consider the following example:
import enum from typing import Any, Optional, Union from PySide6 import QtCore class MyEnum(enum.Enum): CAR = 0 HORSE = 1 BIKE = 2 class VehiclesAndDaysModel(QtCore.QAbstractTableModel): def __init__(self, parent: Optional[QtCore.QObject] = None) -> None: super().__init__(parent=parent) self._dataModel = [ MyEnum.BIKE, MyEnum.CAR, MyEnum.CAR, MyEnum.BIKE, MyEnum.HORSE, ] def columnCount( self, parent: Union[ QtCore.QModelIndex, QtCore.QPersistentModelIndex ] = QtCore.QModelIndex(), ) -> int: return 1 def rowCount( self, parent: Union[ QtCore.QModelIndex, QtCore.QPersistentModelIndex ] = QtCore.QModelIndex(), ) -> int: return len(self._dataModel) def data( self, index: Union[QtCore.QModelIndex, QtCore.QPersistentModelIndex], role: int = QtCore.Qt.ItemDataRole.DisplayRole, ) -> Any: return self._dataModel[index.row()] testModel = VehiclesAndDaysModel() testIndex = testModel.index(2, 0) testData = testModel.data(testIndex) print(type(testData)) print(type(testIndex.data()))
This produces the following output:
<enum 'MyEnum'> <class 'int'>
This is a change in behaviour when upgrading form 6.3.2.
In older versions both statements return the properly typed Enum and I think that's the correct behaviour
Attachments
Issue Links
- duplicates
-
PYSIDE-2339 Enums returned from QAIM::data() get casted to ints for StyledItemDelegate.displayText()
- Closed