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
qqmlitemmodels.qdoc
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page qmodelindex-and-related-classes-in-qml.html
6 \title QModelIndex and related Classes in QML
7
8 Since Qt 5.5, QModelIndex and QPersistentModelIndex are exposed in QML as
9 value-based types. Also exposed in a similar fashion are QModelIndexList,
10 QItemSelectionRange and QItemSelection. All objects from these types can
11 be passed back and forth between QML and C++ as \c var properties or plain
12 JavaScript variables.
13
14 Below you will find an overview of the API exposed to QML for these classes.
15 For more information, refer to their C++ documentation.
16
17 \note Since all these types are exposed as \l{Q_GADGET}{gadgets}, there are no property
18 change notification signals emitted. Therefore binding to their properties
19 may not give the expected results. This is especially true for QPersistentModelIndex.
20
21 \section1 QModelIndex and QPersistentModelIndex Types
22
23 \list
24 \li \b row : int
25 \li \b column : int
26 \li \b parent : QModelIndex
27 \li \b valid : bool
28 \li \b model : QAbstractItemModel
29 \li \b internalId : quint64
30 \endlist
31
32 All these properties are read-only, as are their C++ counterparts. In addition,
33 we also expose the following functions:
34
35 \list
36 \li QVariant \b{data}(int \e role) (since Qt 6.7)
37 \endlist
38
39 \note The usual caveats apply to QModelIndex in QML. If the underlying model changes
40 or gets deleted, it may become dangerous to access its properties. Therefore, you
41 should not store any QModelIndex objects. You can, however, store QPersistentModelIndexe
42 objects in a safe way.
43
44 \section1 QModelIndexList Type
45
46 QModelIndexList is exposed in QML as a JavaScript array. Conversions are
47 automatically made from and to C++. In fact, any JavaScript array can be
48 converted back to QModelIndexList, with non-QModelIndex objects replaced by
49 invalid \l{QModelIndex}es.
50
51 \note QModelIndex to QPersistentModelIndex conversion happens when accessing
52 the array elements because any QModelIndexList property retains reference
53 semantics when exposed this way.
54
55 \section1 \l QItemSelectionRange Type
56
57 \list
58 \li \b top : int
59 \li \b left : int
60 \li \b bottom : int
61 \li \b right : int
62 \li \b width : int
63 \li \b height : int
64 \li \b topLeft : QPersistentModelIndex
65 \li \b bottomRight : QPersistentModelIndex
66 \li \b parent : QModelIndex
67 \li \b valid : bool
68 \li \b empty : bool
69 \li \b model : QAbstractItemModel
70 \endlist
71
72 All these properties are read-only, as are their C++ counterparts. In addition,
73 we also expose the following functions:
74
75 \list
76 \li bool \b{contains}(QModelIndex \e index)
77 \li bool \b{contains}(int \e row, int \e column, QModelIndex \e parentIndex)
78 \li bool \b{intersects}(QItemSelectionRange \e other)
79 \li QItemSelectionRange \b{intersected}(QItemSelectionRange \e other)
80 \endlist
81
82 \section1 QItemSelection Type
83
84 Similarly to QModelIndexList, \l QItemSelection is exposed in QML as a JavaScript
85 array of QItemSelectionRange objects. Conversions are automatically made from and to C++.
86 In fact, any JavaScript array can be converted back to QItemSelection, with
87 non-QItemSelectionRange objects replaced by empty \l {QItemSelectionRange}s.
88
89
90 \sa ItemSelectionModel
91*/