The PySide.QtDeclarative.QDeclarativePropertyMap class allows you to set key-value pairs that can be used in QML bindings.
PySide.QtDeclarative.QDeclarativePropertyMap 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 ownerData = QDeclarativePropertyMap() ownerData.insert("name", "John Smith") ownerData.insert("phone", "555-5555") # expose it to the UI layer view = QDeclarativeView() 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 PySide.QtDeclarative.QDeclarativePropertyMap.valueChanged() signal. However, note that PySide.QtDeclarative.QDeclarativePropertyMap.valueChanged() is NOT emitted when changes are made by calling PySide.QtDeclarative.QDeclarativePropertyMap.insert() or PySide.QtDeclarative.QDeclarativePropertyMap.clear() - 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.
Parameters: | parent – PySide.QtCore.QObject |
---|
Constructs a bindable map with parent object parent .
Parameters: | key – unicode |
---|
Clears the value (if any) associated with key .
Parameters: | key – unicode |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if the map contains key .
Return type: | PySide.QtCore.int |
---|
This is an overloaded function.
Same as PySide.QtDeclarative.QDeclarativePropertyMap.size() .
Parameters: |
|
---|
Sets the value associated with key to value .
If the key doesn’t exist, it is automatically created.
Return type: | PySide.QtCore.bool |
---|
Returns true if the map contains no keys; otherwise returns false.
Return type: | list of strings |
---|
Parameters: | key – unicode |
---|---|
Return type: | object |
This is an overloaded function.
Same as PySide.QtDeclarative.QDeclarativePropertyMap.value() .
Return type: | PySide.QtCore.int |
---|
Returns the number of keys in the map.
Parameters: | key – unicode |
---|---|
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 PySide.QtCore.QVariant is returned.
Parameters: |
|
---|