18int main(
int argc,
char *argv[])
20 QApplication app(argc, argv);
25 QTableView *table =
new QTableView(0);
26 table->setModel(model);
28 QItemSelectionModel *selectionModel = table->selectionModel();
33 QModelIndex bottomRight;
35 topLeft = model->index(0, 0, QModelIndex());
36 bottomRight = model->index(5, 2, QModelIndex());
40 QItemSelection selection(topLeft, bottomRight);
41 selectionModel->select(selection, QItemSelectionModel::Select);
45 QItemSelection toggleSelection;
47 topLeft = model->index(2, 1, QModelIndex());
48 bottomRight = model->index(7, 3, QModelIndex());
49 toggleSelection.select(topLeft, bottomRight);
51 selectionModel->select(toggleSelection, QItemSelectionModel::Toggle);
55 QItemSelection columnSelection;
57 topLeft = model->index(0, 1, QModelIndex());
58 bottomRight = model->index(0, 2, QModelIndex());
60 columnSelection.select(topLeft, bottomRight);
62 selectionModel->select(columnSelection,
63 QItemSelectionModel::Select | QItemSelectionModel::Columns);
65 QItemSelection rowSelection;
67 topLeft = model->index(0, 0, QModelIndex());
68 bottomRight = model->index(1, 0, QModelIndex());
70 rowSelection.select(topLeft, bottomRight);
72 selectionModel->select(rowSelection,
73 QItemSelectionModel::Select | QItemSelectionModel::Rows);
76 table->setWindowTitle(
"Selected items in a table model");
78 table->resize(460, 280);