model中的每个item项都有相关联的数据元素,都有自己的role,这些roles被用于view需要那种类型的model。自定义的model需要返回这些类型的数据。

通用的roles和相关联的种类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Constant          Value Description
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.
数据显示Item提示(QString)
Qt::StatusTipRole 4 The data displayed in the status bar.
数据现在在 status bar中 (QString)
Qt::WhatsThisRole 5 The data displayed for the item in "What's This?" mode.
数据显示在"What's This?"mode中(QString)
Qt::SizeHintRole 13 The size hint for the item that will be supplied to views.
项的大小提供给Views。