Qt 6.x
The Qt SDK
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.
33
34 \note The usual caveats apply to QModelIndex in QML. If the underlying model changes
35 or gets deleted, it may become dangerous to access its properties. Therefore, you
36 should not store any QModelIndex objects. You can, however, store QPersistentModelIndexe
37 objects in a safe way.
38
39 \section1 QModelIndexList Type
40
41 QModelIndexList is exposed in QML as a JavaScript array. Conversions are
42 automatically made from and to C++. In fact, any JavaScript array can be
43 converted back to QModelIndexList, with non-QModelIndex objects replaced by
44 invalid \l{QModelIndex}es.
45
46 \note QModelIndex to QPersistentModelIndex conversion happens when accessing
47 the array elements because any QModelIndexList property retains reference
48 semantics when exposed this way.
49
50 \section1 \l QItemSelectionRange Type
51
52 \list
53 \li \b top : int
54 \li \b left : int
55 \li \b bottom : int
56 \li \b right : int
57 \li \b width : int
58 \li \b height : int
59 \li \b topLeft : QPersistentModelIndex
60 \li \b bottomRight : QPersistentModelIndex
61 \li \b parent : QModelIndex
62 \li \b valid : bool
63 \li \b empty : bool
64 \li \b model : QAbstractItemModel
65 \endlist
66
67 All these properties are read-only, as are their C++ counterparts. In addition,
68 we also expose the following functions:
69
70 \list
71 \li bool \b{contains}(QModelIndex \e index)
72 \li bool \b{contains}(int \e row, int \e column, QModelIndex \e parentIndex)
73 \li bool \b{intersects}(QItemSelectionRange \e other)
74 \li QItemSelectionRange \b{intersected}(QItemSelectionRange \e other)
75 \endlist
76
77 \section1 QItemSelection Type
78
79 Similarly to QModelIndexList, \l QItemSelection is exposed in QML as a JavaScript
80 array of QItemSelectionRange objects. Conversions are automatically made from and to C++.
81 In fact, any JavaScript array can be converted back to QItemSelection, with
82 non-QItemSelectionRange objects replaced by empty \l {QItemSelectionRange}s.
83
84
85 \sa ItemSelectionModel
86*/