Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
8struct MyWidget : public QWidget
9{
10 void wrapper2();
11 void clicked(const QModelIndex &index);
14};
15
16void wrapper0() {
17
20for (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}
27
28} // wrapper0
29
30
31void wrapper1() {
32
35QStandardItem *parentItem = model.invisibleRootItem();
36for (int i = 0; i < 4; ++i) {
37 QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
38 parentItem->appendRow(item);
39 parentItem = item;
40}
42
43} // wrapper1
44
45
48QTreeView *treeView = new QTreeView(this);
51 this, &MyWidget::clicked);
53
54} // wrapper2
55
56
59{
61 // Do stuff with the item ...
62}
64
65
66void wrapper3() {
67QTreeView *treeView = nullptr;
68MyWidget *item = nullptr;
70treeView->scrollTo(item->index());
72
73} // wrapper3
74} // src_gui_itemviews_qstandarditemmodel
void clicked(const QModelIndex &index)
This signal is emitted when a mouse button is left-clicked.
\inmodule QtCore
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
int rowCount(const QModelIndex &parent=QModelIndex()) const override
If the database supports returning the size of a query (see QSqlDriver::hasFeature()),...
int columnCount(const QModelIndex &parent=QModelIndex()) const override
\reimp
The QStandardItemModel class provides a generic model for storing custom data.
QStandardItem * itemFromIndex(const QModelIndex &index) const
The QStandardItem class provides an item for use with the QStandardItemModel class.
void appendRow(const QList< QStandardItem * > &items)
Appends a row containing items.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTreeView class provides a default model/view implementation of a tree view.
Definition qtreeview.h:20
void setModel(QAbstractItemModel *model) override
\reimp
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible) override
Scroll the contents of the tree view until the given model item index is visible.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
GLuint index
[2]
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
SSL_CTX int void * arg
QSqlQueryModel * model
[16]
QGraphicsItem * item