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
cpp-tablemodel.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#ifndef CPPTABLEMODEL_H
5#define CPPTABLEMODEL_H
6
7//![0]
8#include <qqml.h>
9#include <QAbstractTableModel>
10
11class TableModel : public QAbstractTableModel
12{
13 Q_OBJECT
14 QML_ELEMENT
15
16public:
17 int rowCount(const QModelIndex & = QModelIndex()) const override
18 {
19 return 200;
20 }
21
22 int columnCount(const QModelIndex & = QModelIndex()) const override
23 {
24 return 200;
25 }
26
27 QVariant data(const QModelIndex &index, int role) const override
28 {
29 switch (role) {
30 case Qt::DisplayRole:
31 return QString("%1, %2").arg(index.column()).arg(index.row());
32 default:
33 break;
34 }
35
36 return QVariant();
37 }
38
39 QHash<int, QByteArray> roleNames() const override
40 {
41 return { {Qt::DisplayRole, "display"} };
42 }
43};
44//![0]
45
46#endif // CPPTABLEMODEL_H
int main(int argc, char *argv[])
[ctor_close]