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
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#include <QtGui>
5#include <QApplication>
6#include <QSortFilterProxyModel>
7
9{
10public:
11 MyItemModel(QWidget *parent = nullptr);
12};
13
17
18class Widget : public QWidget
19{
20public:
21 Widget(QWidget *parent = nullptr);
22};
23
25 : QWidget(parent)
26{
28 QTreeView *treeView = new QTreeView;
30 MyItemModel *model = new MyItemModel(this);
31
32 treeView->setModel(model);
34
36 MyItemModel *sourceModel = new MyItemModel(this);
37 QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
38
39 proxyModel->setSourceModel(sourceModel);
40 treeView->setModel(proxyModel);
42
44 treeView->setSortingEnabled(true);
46
48 proxyModel->sort(2, Qt::AscendingOrder);
51 proxyModel->setFilterKeyColumn(1);
53}
54
55int main(int argc, char *argv[])
56{
57 QApplication app(argc, argv);
59 widget.show();
60 return app.exec();
61}
MyItemModel(QWidget *parent=nullptr)
Definition main.cpp:14
The QApplication class manages the GUI application's control flow and main settings.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore \reentrant
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
\reimp Sorts the model by column in the given order.
void setSourceModel(QAbstractItemModel *sourceModel) override
\reimp
void setFilterRegularExpression(const QString &pattern)
The QStandardItemModel class provides a generic model for storing custom data.
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
The QTreeView class provides a default model/view implementation of a tree view.
Definition qtreeview.h:20
void setModel(QAbstractItemModel *model) override
\reimp
void setSortingEnabled(bool enable)
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
Widget(QWidget *parent=nullptr)
Definition main.cpp:24
QOpenGLWidget * widget
[1]
int main()
[0]
@ AscendingOrder
Definition qnamespace.h:122
QSqlQueryModel * model
[16]
QApplication app(argc, argv)
[0]