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)

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.


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 ] )
参数: parent PySide.QtCore.QObject

Constructs a bindable map with parent object parent .

PySide.QtDeclarative.QDeclarativePropertyMap. clear ( key )
参数: key – unicode

Clears the value (if any) associated with key .

PySide.QtDeclarative.QDeclarativePropertyMap. contains ( key )
参数: key – unicode
返回类型: PySide.QtCore.bool

Returns true if the map contains key .

PySide.QtDeclarative.QDeclarativePropertyMap. count ( )
返回类型: PySide.QtCore.int


如同 PySide.QtDeclarative.QDeclarativePropertyMap.size() .

PySide.QtDeclarative.QDeclarativePropertyMap. insert ( key , value )
  • 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 ( )
返回类型: PySide.QtCore.bool

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

PySide.QtDeclarative.QDeclarativePropertyMap. keys ( )
返回类型: list of strings
参数: key – unicode
返回类型: object


如同 PySide.QtDeclarative.QDeclarativePropertyMap.value() .

PySide.QtDeclarative.QDeclarativePropertyMap. size ( )
返回类型: PySide.QtCore.int

Returns the number of keys in the map.

PySide.QtDeclarative.QDeclarativePropertyMap. value ( key )
参数: key – unicode
返回类型: 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 被返回。

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