setModel()來實現view 的model顯示
modelindex 是用來在model里面定位數據的,他是QAbstractItemModel的子類
通過item view,delegates,selection models,在model里來定位一個item。
每個index由三部分組成:row,column,和表面model的指針,對於一維列表,column永遠為0
QAbstractItemModel 的函數
rowCount();columnCount();獲取行和列
InsertRows();InsertColumns();RomoveRows();RemoveColumns();插入,刪除行列
sibling()返回同級別地址,沒有同級別不返回
[virtual] QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const
data() 返回根據index提取數據 QVariant:變體
[pure virtual] QVariant QAbstractItemModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const
模型中的一個數據項會存放多個數據子項,其中一些是應用程序需要處理的數據,另外一些是model/view框架中其他部分需要處理的(視圖對象/代理對象)
我們把數據子項所起的作用稱為role(角色),因此我們認為一個數據項是多個“角色,數據子項”的集合。
DisplayRole 如標題是一個數據子項,
DecorotionRole 圖標是一個數據子項 ,
ToolTipRole 鼠標停在上面要顯示的文字提示框也是一個數據子項,
UserRole 存放用戶具體應用的數據,
StatusTipRole 鼠標停在數據區,狀態欄要顯示的文字
WhatsThisRole 用戶對數據執行“whats this"命令時要顯示的文字
SizeHintRole 一個數據項占據屏幕的尺寸
所有數據子項都具有變體QVariant,不同的子項變體內容類型不同