Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4/*
5 main.cpp
6
7 A simple example that shows how selections can be used directly on a model.
8 It shows the result of some selections made using a table view.
9*/
10
11#include <QApplication>
12#include <QItemSelection>
13#include <QItemSelectionModel>
14#include <QTableView>
15
16#include "../common-table-model/model.h"
17
18int main(int argc, char *argv[])
19{
20 QApplication app(argc, argv);
21
22 //! [0]
23 TableModel *model = new TableModel(8, 4, &app);
24
25 QTableView *table = new QTableView(0);
26 table->setModel(model);
27
28 QItemSelectionModel *selectionModel = table->selectionModel();
29 //! [0]
30
31 //! [1]
32 QModelIndex topLeft;
33 QModelIndex bottomRight;
34
35 topLeft = model->index(0, 0, QModelIndex());
36 bottomRight = model->index(5, 2, QModelIndex());
37 //! [1]
38
39 //! [2]
40 QItemSelection selection(topLeft, bottomRight);
41 selectionModel->select(selection, QItemSelectionModel::Select);
42 //! [2]
43
44 //! [3]
45 QItemSelection toggleSelection;
46
47 topLeft = model->index(2, 1, QModelIndex());
48 bottomRight = model->index(7, 3, QModelIndex());
49 toggleSelection.select(topLeft, bottomRight);
50
51 selectionModel->select(toggleSelection, QItemSelectionModel::Toggle);
52 //! [3]
53
54 //! [4]
55 QItemSelection columnSelection;
56
57 topLeft = model->index(0, 1, QModelIndex());
58 bottomRight = model->index(0, 2, QModelIndex());
59
60 columnSelection.select(topLeft, bottomRight);
61
62 selectionModel->select(columnSelection,
63 QItemSelectionModel::Select | QItemSelectionModel::Columns);
64
65 QItemSelection rowSelection;
66
67 topLeft = model->index(0, 0, QModelIndex());
68 bottomRight = model->index(1, 0, QModelIndex());
69
70 rowSelection.select(topLeft, bottomRight);
71
72 selectionModel->select(rowSelection,
73 QItemSelectionModel::Select | QItemSelectionModel::Rows);
74 //! [4]
75
76 table->setWindowTitle("Selected items in a table model");
77 table->show();
78 table->resize(460, 280);
79 return app.exec();
80}
[0]
Definition model.h:12
int main(int argc, char *argv[])
[ctor_close]