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
src_gui_itemviews_qstandarditemmodel.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
#
include
<
QStandardItemModel
>
4
#
include
<
QTreeView
>
5
#
include
<
QWidget
>
6
7
namespace
src_gui_itemviews_qstandarditemmodel
{
8
struct
MyWidget
:
public
QWidget
9
{
10
void
wrapper2
();
11
void
clicked
(
const
QModelIndex &index);
12
QModelIndex
index
() {
return
QModelIndex(); }
13
QStandardItemModel
*
myStandardItemModel
;
14
};
15
16
void
wrapper0
() {
17
18
//! [0]
19
QStandardItemModel model(4, 4);
20
for
(
int
row = 0; row < model.rowCount(); ++row) {
21
for
(
int
column = 0; column < model.columnCount(); ++column) {
22
QStandardItem *item =
new
QStandardItem(QString(
"row %0, column %1"
).arg(row).arg(column));
23
model.setItem(row, column, item);
24
}
25
}
26
//! [0]
27
28
}
// wrapper0
29
30
31
void
wrapper1
() {
32
33
//! [1]
34
QStandardItemModel model;
35
QStandardItem *parentItem = model.invisibleRootItem();
36
for
(
int
i = 0; i < 4; ++i) {
37
QStandardItem *item =
new
QStandardItem(QString(
"item %0"
).arg(i));
38
parentItem->appendRow(item);
39
parentItem = item;
40
}
41
//! [1]
42
43
}
// wrapper1
44
45
46
void
MyWidget
::
wrapper2
() {
47
//! [2]
48
QTreeView *treeView =
new
QTreeView(
this
);
49
treeView->setModel(myStandardItemModel);
50
connect(treeView, &QTreeView::clicked,
51
this
, &MyWidget::clicked);
52
//! [2]
53
54
}
// wrapper2
55
56
57
//! [3]
58
void
MyWidget
::
clicked
(
const
QModelIndex &index)
59
{
60
QStandardItem *item = myStandardItemModel->itemFromIndex(index);
61
// Do stuff with the item ...
62
}
63
//! [3]
64
65
66
void
wrapper3
() {
67
QTreeView *treeView =
nullptr
;
68
MyWidget
*item =
nullptr
;
69
//! [4]
70
treeView->scrollTo(item->index());
71
//! [4]
72
73
}
// wrapper3
74
}
// src_gui_itemviews_qstandarditemmodel
src_gui_itemviews_qstandarditemmodel
Definition
src_gui_itemviews_qstandarditemmodel.cpp:7
src_gui_itemviews_qstandarditemmodel::wrapper3
void wrapper3()
[3]
Definition
src_gui_itemviews_qstandarditemmodel.cpp:66
src_gui_itemviews_qstandarditemmodel::wrapper0
void wrapper0()
Definition
src_gui_itemviews_qstandarditemmodel.cpp:16
src_gui_itemviews_qstandarditemmodel::wrapper1
void wrapper1()
Definition
src_gui_itemviews_qstandarditemmodel.cpp:31
src_gui_itemviews_qstandarditemmodel::MyWidget
Definition
src_gui_itemviews_qstandarditemmodel.cpp:9
src_gui_itemviews_qstandarditemmodel::MyWidget::index
QModelIndex index()
Definition
src_gui_itemviews_qstandarditemmodel.cpp:12
src_gui_itemviews_qstandarditemmodel::MyWidget::clicked
void clicked(const QModelIndex &index)
[3]
Definition
src_gui_itemviews_qstandarditemmodel.cpp:58
src_gui_itemviews_qstandarditemmodel::MyWidget::wrapper2
void wrapper2()
Definition
src_gui_itemviews_qstandarditemmodel.cpp:46
src_gui_itemviews_qstandarditemmodel::MyWidget::myStandardItemModel
QStandardItemModel * myStandardItemModel
Definition
src_gui_itemviews_qstandarditemmodel.cpp:13
qtbase
src
gui
doc
snippets
code
src_gui_itemviews_qstandarditemmodel.cpp
Generated on
for Qt by
1.18.0