In my reimplementation of QStandardItem
I am implementing setData
. I understand how roles work in general, and their integer representation (see below for a full enumeration from the docs) , but am getting a role that is not in the usual enumeration: a role with constant 31. What is this mysterious undocumented role?
Here is my QStandardItem
subclass (note this isn't something I am actually using, but something just to make this question more clear):
class StandardItem(QtGui.QStandardItem):
def setData(self, newValue, role=QtCore.Qt.UserRole + 1):
if role == QtCore.Qt.EditRole:
print "setData for editRole"
QtGui.QStandardItem.setData(self, newValue, role)
return True
if role == QtCore.Qt.CheckStateRole:
print "setData for check state role"
QtGui.QStandardItem.setData(self, newValue, role)
return True
print "setData for other cases, with role ", role
QtGui.QStandardItem.setData(self, newValue, role)
Overall I see things that are reasonable, except I see role number 31 too printed out when I view my model:
setData for check state role
setData for other than editRole: 31
In the enumeration of the roles, I don't find role 31 (I cut/paste the entire list of roles, just in case I am being totally obtuse):
Role Constant Desc
Qt.DisplayRole 0 The key data to be rendered in the form of text. (QString)
Qt.DecorationRole 1 The data to be rendered as a decoration in the form of an icon. (QColor, QIcon or QPixmap)
Qt.EditRole 2 The data in a form suitable for editing in an editor. (QString)
Qt.ToolTipRole 3 The data displayed in the item's tooltip. (QString)
Qt.StatusTipRole 4 The data displayed in the status bar. (QString)
Qt.WhatsThisRole 5 The data displayed for the item in "What's This?" mode. (QString)
Qt.SizeHintRole 13 The size hint for the item that will be supplied to views. (QSize)
Qt.FontRole 6 The font used for items rendered with the default delegate. (QFont)
Qt.TextAlignmentRole 7 The alignment of the text for items rendered with the default delegate. (Qt.AlignmentFlag)
Qt.BackgroundRole 8 The background brush used for items rendered with the default delegate. (QBrush)
Qt.BackgroundColorRole 8 This role is obsolete. Use BackgroundRole instead.
Qt.ForegroundRole 9 The foreground brush (text color, typically) used for items rendered with the default delegate. (QBrush)
Qt.TextColorRole 9 This role is obsolete. Use ForegroundRole instead.
Qt.CheckStateRole 10 This role is used to obtain the checked state of an item. (Qt.CheckState)
Qt.InitialSortOrderRole 14 This role is used to obtain the initial sort order of a header view section. (Qt.SortOrder). This role was introduced in Qt 4.8.
Qt.AccessibleTextRole 11 The text to be used by accessibility extensions and plugins, such as screen readers. (QString)
Qt.AccessibleDescriptionRole 12 A description of the item for accessibility purposes. (QString)
Qt.UserRole 32 The first role that can be used for application-specific purposes.
Does anyone know what role 31 is?