QDeclarativePropertyMap

Inheritance diagram of QDeclarativePropertyMap

Synopsis

Functions

Signals

Detailed Description

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.

class PySide.QtDeclarative.QDeclarativePropertyMap([parent=None])
Parameters:parentPySide.QtCore.QObject

Constructs a bindable map with parent object parent .

PySide.QtDeclarative.QDeclarativePropertyMap.clear(key)
Parameters:key – unicode

Clears the value (if any) associated with key .

PySide.QtDeclarative.QDeclarativePropertyMap.contains(key)
Parameters:key – unicode
Return type:PySide.QtCore.bool

Returns true if the map contains key .

PySide.QtDeclarative.QDeclarativePropertyMap.count()
Return type:PySide.QtCore.int

This is an overloaded function.

Same as PySide.QtDeclarative.QDeclarativePropertyMap.size() .

PySide.QtDeclarative.QDeclarativePropertyMap.insert(key, value)
Parameters:
  • key – unicode
  • value – object

Sets the value associated with key to value .

If the key doesn’t exist, it is automatically created.

PySide.QtDeclarative.QDeclarativePropertyMap.isEmpty()
Return type:PySide.QtCore.bool

Returns true if the map contains no keys; otherwise returns false.

PySide.QtDeclarative.QDeclarativePropertyMap.keys()
Return type:list of strings
PySide.QtDeclarative.QDeclarativePropertyMap.operator[](key)
Parameters:key – unicode
Return type:object

This is an overloaded function.

Same as PySide.QtDeclarative.QDeclarativePropertyMap.value() .

PySide.QtDeclarative.QDeclarativePropertyMap.size()
Return type:PySide.QtCore.int

Returns the number of keys in the map.

PySide.QtDeclarative.QDeclarativePropertyMap.value(key)
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.

PySide.QtDeclarative.QDeclarativePropertyMap.valueChanged(key, value)
Parameters:
  • key – unicode
  • value – object