rock1411的个人主页

http://www.qtcn.org/bbs/u/137197  [收藏] [复制]

rock1411

  • 0

    关注

  • 0

    粉丝

  • 3

    访客

  • 等级:新手上路
  • 总积分:2
  • 保密,1971-01-01

最后登录:2019-09-12

更多资料

日志

QModelIndex

2012-10-20 10:19
The QModelIndex class is used to locate data in a data model.The index is used by item views, delegates, and selectionmodels to locate an item in the model.
Aselection model belonging to one view can be obtained using the view's selectionModel() function, and sharedbetween many views with setSelectionModel(),so the construction of new selection models is generally not required.
weconstruct an instance of a custom table model with 32 items in total, and opena table view onto its data. The table view's default selection model isretrieved for later use:
TableModel *model = new TableModel(8,4, &app);
QTableView *table = new QTableView(0);
table->setModel(model);
QItemSelectionModel *selectionModel
= table->selectionModel();
Weselect the model indexes corresponding to the top-left and bottom-right itemsin the region to be selected:
QModelIndextopLeft;
QModelIndexbottomRight;
topLeft= model->index(0, 0, QModelIndex());
bottomRight= model->index(5, 2, QModelIndex());
To select these items in the model, and seethe corresponding change in the table view, we need to construct a selectionobject then apply it to the selection model:
QItemSelectionselection(topLeft, bottomRight);
selectionModel->
select(selection,QItemSelectionModel::Select);

Themodel indexes stored in the selection model can be read using theselectedIndexes() function.
QModelIndexListindexes = selectionModel->selectedIndexes();
QModelIndexindex;

foreach(index,indexes) {
QString textQString("(%1,%2)").arg(index.row()).arg(index.column());
model->setData(index, text);[size=font-size:12.0pt,12.0pt][font=&amp]}
分类:默认分类|回复:0|浏览:4184|全站可见|转载
 

下一篇: Qt5 C++源码中使用中文的简单步骤

上一篇:

Powered by phpwind v8.7 Certificate Copyright Time now is:05-19 09:22
©2005-2016 QTCN开发网 版权所有 Gzip disabled