[QtDeclarative module]
该QDeclarativePropertyMap类允许您设置,可以在QML绑定使用键 - 值对。More…
继承QObject。
Methods
__init__ (self, QObject parent = None)
clear (self, QString key)
bool contains (self, QString key)
int count (self)
insert (self, QString key, QVariant value)
bool isEmpty (self)
QStringList keys (self)
int size (self)
QVariant value (self, QString key)
Special Methods
QVariant __getitem__ (self, QString key)
__len__ (self)
Qt Signals
void valueChanged (const QString&,const QVariant&)
Detailed Description
该QDeclarativePropertyMap类允许您设置,可以在QML绑定使用键 - 值对。
QDeclarativePropertyMap提供了一个方便的方式来域数据暴露给UI层。下面的例子显示了如何声明在C + +的数据,然后访问它的QML 。
在C + +中的文件:
// create our data
QDeclarativePropertyMap ownerData;
ownerData.insert("name", [QVariant](docs_qvariant.html)([QString](docs_qstring.html)("John Smith")));
ownerData.insert("phone", [QVariant](docs_qvariant.html)([QString](docs_qstring.html)("555-5555")));
// expose it to the UI layer
[QDeclarativeView](docs_qdeclarativeview.html) view;
[QDeclarativeContext](docs_qdeclarativecontext.html) *ctxt = view.rootContext();
ctxt->setContextProperty("owner", &ownerData);
view.setSource([QUrl](docs_qurl.html).fromLocalFile("main.qml"));
view.show();
然后,在main.qml
:
Text { text: owner.name + " " + owner.phone }
绑定是动态的 - 每当一个键的值被更新,什么都绑定到该密钥将更新。
为了检测在UI层做值的变化可以连接到valueChanged()信号。但是请注意,valueChanged()是NOT更改时通过调用发出的制作insert()或clear() - 它是仅当一个值被从QML更新射出。
Note:这是不可能的,从地图中删除键,一旦一个密钥被添加,你只能修改或清除其关联的值。
Method Documentation
QDeclarativePropertyMap.__init__ (self, QObject parent = None)
该parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。
构造一个可绑定的地图与父对象parent。
QDeclarativePropertyMap.clear (self, QString key)
清除值(如果有的话)与关联key。
bool QDeclarativePropertyMap.contains (self, QString key)
如果地图包含,则返回Truekey。
See also size( ) 。
int QDeclarativePropertyMap.count (self)
这是一个重载函数。
同size( ) 。
QDeclarativePropertyMap.insert (self, QString key, QVariant value)
设置关联的值key至value。
如果该键不存在,则会自动创建。
bool QDeclarativePropertyMap.isEmpty (self)
返回True如果映射不包含键,否则返回False 。
See also size( ) 。
QStringList QDeclarativePropertyMap.keys (self)
返回键的列表。
已清除键仍然会出现在这个列表中,即使它们相关的值是无效的QVariants。
int QDeclarativePropertyMap.size (self)
返回键映射中的号码。
QVariant QDeclarativePropertyMap.value (self, QString key)
返回与关联的值key。
如果没有值被设置为这个键(或如果该值已被清除) ,无效QVariant返回。
QVariant QDeclarativePropertyMap.__getitem__ (self, QString key)
QDeclarativePropertyMap.__len__ (self)
Qt Signal Documentation
void valueChanged (const QString&,const QVariant&)
这是该信号的默认超载。
这个信号被发射时在地图中的一个值被改变。key是对应于该键value已更改。
Note:的valueChanged ()是NOT更改时通过调用发出的制作insert()或clear() - 它是仅当一个值被从QML更新射出。