QQmlListReference¶
The
QQmlListReference
class allows the manipulation ofQQmlListProperty
properties. More…
Synopsis¶
Functions¶
def
append
(arg__1)def
at
(arg__1)def
canAppend
()def
canAt
()def
canClear
()def
canCount
()def
canRemoveLast
()def
canReplace
()def
clear
()def
count
()def
isManipulable
()def
isReadable
()def
isValid
()def
listElementType
()def
object
()def
removeLast
()def
replace
(arg__1, arg__2)
Detailed Description¶
QQmlListReference
allows C++ programs to read from, and assign values to a QML list property in a simple and type-safe way. AQQmlListReference
can be created by passing an object and property name or through aQQmlProperty
instance. These two are equivalent:QQmlListReference ref1(object, "children"); QQmlProperty ref2(object, "children"); QQmlListReference ref2 = qvariant_cast<QQmlListReference>(ref2.read());Not all QML list properties support all operations. A set of methods,
canAppend()
,canAt()
,canClear()
andcanCount()
allow programs to query whether an operation is supported on a given property.QML list properties are type-safe. Only
QObject
‘s that derive from the correct base class can be assigned to the list. ThelistElementType()
method can be used to query theQMetaObject
of theQObject
type supported. Attempting to add objects of the incorrect type to a list property will fail.Like with normal lists, when accessing a list element by index, it is the callers responsibility to ensure that it does not request an out of range element using the
count()
method before callingat()
.
- class PySide2.QtQml.QQmlListReference¶
PySide2.QtQml.QQmlListReference(arg__1, property[, arg__3=None])
PySide2.QtQml.QQmlListReference(arg__1)
- param property:
str
- param arg__1:
- param arg__3:
Constructs an invalid instance.
Constructs a
QQmlListReference
forobject
‘sproperty
. Ifproperty
is not a list property, an invalidQQmlListReference
is created. Ifobject
is destroyed after the reference is constructed, it will automatically become invalid. That is, it is safe to holdQQmlListReference
instances even afterobject
is deleted.Passing
engine
is required to access some QML created list properties. If in doubt, and an engine is available, pass it.
- PySide2.QtQml.QQmlListReference.append(arg__1)¶
- Parameters:
arg__1 –
PySide2.QtCore.QObject
- Return type:
bool
Appends
object
to the list. Returns true if the operation succeeded, otherwise false.See also
- PySide2.QtQml.QQmlListReference.at(arg__1)¶
- Parameters:
arg__1 – int
- Return type:
Returns the list element at
index
, or 0 if the operation failed.See also
- PySide2.QtQml.QQmlListReference.canAppend()¶
- Return type:
bool
Returns true if the list property can be appended to, otherwise false. Returns false if the reference is invalid.
See also
- PySide2.QtQml.QQmlListReference.canAt()¶
- Return type:
bool
Returns true if the list property can queried by index, otherwise false. Returns false if the reference is invalid.
See also
- PySide2.QtQml.QQmlListReference.canClear()¶
- Return type:
bool
Returns true if the list property can be cleared, otherwise false. Returns false if the reference is invalid.
See also
- PySide2.QtQml.QQmlListReference.canCount()¶
- Return type:
bool
Returns true if the list property can be queried for its element count, otherwise false. Returns false if the reference is invalid.
See also
- PySide2.QtQml.QQmlListReference.canRemoveLast()¶
- Return type:
bool
Returns true if the last item can be removed from the list property, otherwise false. Returns false if the reference is invalid.
See also
- PySide2.QtQml.QQmlListReference.canReplace()¶
- Return type:
bool
Returns true if items in the list property can be replaced, otherwise false. Returns false if the reference is invalid.
See also
- PySide2.QtQml.QQmlListReference.clear()¶
- Return type:
bool
Clears the list. Returns true if the operation succeeded, otherwise false.
See also
- PySide2.QtQml.QQmlListReference.count()¶
- Return type:
int
Returns the number of objects in the list, or 0 if the operation failed.
- PySide2.QtQml.QQmlListReference.isManipulable()¶
- Return type:
bool
Return true if
at()
,count()
,append()
, and eitherclear()
orremoveLast()
are implemented, so you can manipulate the list.Mind that
replace()
andremoveLast()
can be emulated by stashing all items and rebuilding the list usingclear()
andappend()
. Therefore, they are not required for the list to be manipulable. Furthermore,clear()
can be emulated usingremoveLast()
.See also
isReadable()
at()
count()
append()
clear()
replace()
removeLast()
- PySide2.QtQml.QQmlListReference.isReadable()¶
- Return type:
bool
Return true if
at()
andcount()
are implemented, so you can access the elements.See also
- PySide2.QtQml.QQmlListReference.isValid()¶
- Return type:
bool
Returns true if the instance refers to a valid list property, otherwise false.
- PySide2.QtQml.QQmlListReference.listElementType()¶
- Return type:
Returns the
QMetaObject
for the elements stored in the list property, orNone
if the reference is invalid.The
QMetaObject
can be used ahead of time to determine whether a given instance can be added to a list.
- PySide2.QtQml.QQmlListReference.object()¶
- Return type:
Returns the list property’s object. Returns
None
if the reference is invalid.
- PySide2.QtQml.QQmlListReference.removeLast()¶
- Return type:
bool
Removes the last item in the list. Returns true if the operation succeeded, otherwise false.
See also
- PySide2.QtQml.QQmlListReference.replace(arg__1, arg__2)¶
- Parameters:
arg__1 – int
arg__2 –
PySide2.QtCore.QObject
- Return type:
bool
Replaces the item at
index
in the list withobject
. Returns true if the operation succeeded, otherwise false.See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.