QQmlPropertyMap¶
The
QQmlPropertyMap
class allows you to set key-value pairs that can be used in QML bindings. More…
Synopsis¶
Functions¶
Virtual functions¶
def
updateValue
(key, input)
Signals¶
def
valueChanged
(key, value)
Detailed Description¶
QQmlPropertyMap
provides a convenient way to expose domain data to the UI layer. The following example shows how you might declare data in C++ and then access it in QML.In the C++ file:
// create our data QQmlPropertyMap ownerData; ownerData.insert("name", QVariant(QString("John Smith"))); ownerData.insert("phone", QVariant(QString("555-5555"))); // expose it to the UI layer QQuickView view; QQmlContext *ctxt = view.rootContext(); ctxt->setContextProperty("owner", &ownerData); view.setSource(QUrl::fromLocalFile("main.qml")); view.show();Then, in
main.qml
:Text { text: owner.name + " " + owner.phone }The binding is dynamic - whenever a key’s value is updated, anything bound to that key will be updated as well.
To detect value changes made in the UI layer you can connect to the
valueChanged()
signal. However, note thatvalueChanged()
is NOT emitted when changes are made by callinginsert()
orclear()
- it is only emitted when a value is updated from QML.Note
It is not possible to remove keys from the map; once a key has been added, you can only modify or clear its associated value.
Note
When deriving a class from
QQmlPropertyMap
, use theprotected two-argument constructor
which ensures that the class is correctly registered with the Qt Meta-Object System .Note
The
QMetaObject
of aQQmlPropertyMap
is dynamically generated and modified. Operations on that meta object are not thread safe, so applications need to take care to explicitly synchronize access to the meta object.
- class PySide2.QtQml.QQmlPropertyMap([parent=None])¶
- param parent:
Constructs a bindable map with parent object
parent
.
- PySide2.QtQml.QQmlPropertyMap.clear(key)¶
- Parameters:
key – str
Clears the value (if any) associated with
key
.
- PySide2.QtQml.QQmlPropertyMap.contains(key)¶
- Parameters:
key – str
- Return type:
bool
Returns true if the map contains
key
.See also
- PySide2.QtQml.QQmlPropertyMap.count()¶
- Return type:
int
This is an overloaded function.
Same as
size()
.
- PySide2.QtQml.QQmlPropertyMap.insert(key, value)¶
- Parameters:
key – str
value – object
Sets the value associated with
key
tovalue
.If the key doesn’t exist, it is automatically created.
- PySide2.QtQml.QQmlPropertyMap.isEmpty()¶
- Return type:
bool
Returns true if the map contains no keys; otherwise returns false.
See also
- PySide2.QtQml.QQmlPropertyMap.keys()¶
- Return type:
list of strings
Returns the list of keys.
Keys that have been cleared will still appear in this list, even though their associated values are invalid QVariants.
- PySide2.QtQml.QQmlPropertyMap.operator[](key)
- Parameters:
key – str
- Return type:
object
This is an overloaded function.
Same as
value()
.
- PySide2.QtQml.QQmlPropertyMap.size()¶
- Return type:
int
Returns the number of keys in the map.
- PySide2.QtQml.QQmlPropertyMap.updateValue(key, input)¶
- Parameters:
key – str
input – object
- Return type:
object
Returns the new value to be stored for the key
key
. This function is provided to intercept updates to a property from QML, where the value provided from QML isinput
.Override this function to manipulate the property value as it is updated. Note that this function is only invoked when the value is updated from QML.
- PySide2.QtQml.QQmlPropertyMap.value(key)¶
- Parameters:
key – str
- Return type:
object
Returns the value associated with
key
.If no value has been set for this key (or if the value has been cleared), an invalid
QVariant
is returned.
- PySide2.QtQml.QQmlPropertyMap.valueChanged(key, value)¶
- Parameters:
key – str
value – object
© 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.