Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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 a single model can be shared between
8
multiple views.
9
*/
10
11
#
include
<
QApplication
>
12
#
include
<
QHeaderView
>
13
#
include
<
QItemSelectionModel
>
14
#
include
<
QTableView
>
15
16
#
include
"../common-table-model/model.h"
17
18
int
main
(
int
argc,
char
*argv[])
19
{
20
QApplication app(argc, argv);
21
22
TableModel
*model =
new
TableModel
(4, 2, &app);
23
24
//! [0]
25
QTableView *firstTableView =
new
QTableView;
26
QTableView *secondTableView =
new
QTableView;
27
//! [0]
28
29
//! [1]
30
firstTableView->setModel(model);
31
secondTableView->setModel(model);
32
//! [1]
33
34
firstTableView->horizontalHeader()->setModel(model);
35
36
for
(
int
row = 0; row < 4; ++row) {
37
for
(
int
column = 0; column < 2; ++column) {
38
QModelIndex index = model->index(row, column, QModelIndex());
39
model->setData(index, QVariant(QString(
"(%1, %2)"
).arg(row).arg(column)));
40
}
41
}
42
43
//! [2]
44
secondTableView->setSelectionModel(firstTableView->selectionModel());
45
//! [2]
46
47
firstTableView->setWindowTitle(
"First table view"
);
48
secondTableView->setWindowTitle(
"Second table view"
);
49
firstTableView->show();
50
secondTableView->show();
51
return
app.exec();
52
}
TableModel
[0]
Definition
model.h:12
main
int main(int argc, char *argv[])
[ctor_close]
Definition
src_corelib_animation_qpropertyanimation.cpp:100
qtbase
src
widgets
doc
snippets
sharedtablemodel
main.cpp
Generated on
for Qt by
1.18.0