QDeclarativeProperty Class Reference

[ QtDeclarative module]

The QDeclarativeProperty class abstracts accessing properties on objects created from QML. 更多...

类型

方法

Static Methods

Special Methods


详细描述

The QDeclarativeProperty class abstracts accessing properties on objects created from QML.

As QML uses Qt's meta-type system all of the existing QMetaObject classes can be used to introspect and interact with objects created by QML. However, some of the new features provided by QML - such as type safety and attached properties - are most easily used through the QDeclarativeProperty class that simplifies some of their natural complexity.

不像 QMetaProperty which represents a property on a class type, QDeclarativeProperty encapsulates a property on a specific object instance. To read a property's value, programmers create a QDeclarativeProperty instance and call the read () method. Likewise to write a property value the write () method is used.

For example, for the following QML code:

 // MyItem.qml
 import QtQuick 1.0
 Text { text: "A bit of text" }
			

文本 object's properties could be accessed using QDeclarativeProperty, like this:

 #include <QDeclarativeProperty>
 #include <QGraphicsObject>
 ...
 QDeclarativeView view(QUrl.fromLocalFile("MyItem.qml"));
 QDeclarativeProperty property(view.rootObject(), "font.pixelSize");
 qWarning() << "Current pixel size:" << property.read().toInt();
 property.write(24);
 qWarning() << "Pixel size should now be 24:" << property.read().toInt();
			

类型文档编制

QDeclarativeProperty.PropertyTypeCategory

This enum specifies a category of QML property.

常量 描述
QDeclarativeProperty.InvalidCategory 0 The property is invalid, or is a signal 特性。
QDeclarativeProperty.List 1 The property is a QDeclarativeListProperty list property
QDeclarativeProperty.Object 2 The property is a QObject derived type pointer
QDeclarativeProperty.Normal 3 The property is a normal value property.

QDeclarativeProperty.Type

This enum specifies a type of QML property.

常量 描述
QDeclarativeProperty.Invalid 0 The property is invalid.
QDeclarativeProperty.Property 1 The property is a regular Qt property.
QDeclarativeProperty.SignalProperty 2 The property is a signal property.

方法文档编制

QDeclarativeProperty.__init__ ( self )

Create an invalid QDeclarativeProperty .

QDeclarativeProperty.__init__ ( self , QObject )

创建 QDeclarativeProperty 为 default property of obj . If there is no default property, an invalid QDeclarativeProperty 将是 created.

QDeclarativeProperty.__init__ ( self , QObject , QDeclarativeContext )

创建 QDeclarativeProperty 为 default property of obj 使用 context ctxt . If there is no default property, an invalid QDeclarativeProperty 将是 created.

QDeclarativeProperty.__init__ ( self , QObject , QDeclarativeEngine )

创建 QDeclarativeProperty 为 default property of obj using the environment for instantiating QML components that is provided by engine 。若 there is no default property, an invalid QDeclarativeProperty 将是 created.

QDeclarativeProperty.__init__ ( self , QObject , QString)

创建 QDeclarativeProperty 为 property name of obj .

QDeclarativeProperty.__init__ ( self , QObject , QString, QDeclarativeContext )

创建 QDeclarativeProperty 为 property name of obj 使用 context ctxt .

Creating a QDeclarativeProperty without a context will render some properties - like attached properties - inaccessible.

QDeclarativeProperty.__init__ ( self , QObject , QString, QDeclarativeEngine )

创建 QDeclarativeProperty 为 property name of obj using the environment for instantiating QML components that is provided by engine .

QDeclarativeProperty.__init__ ( self , QDeclarativeProperty )

Create a copy of other .

bool QDeclarativeProperty.connectNotifySignal ( self , QObject   dest , SLOT()SLOT()  slot )

Connects the property's change notifier signal to the specified slot dest object and returns true. Returns false if this metaproperty does not represent a regular Qt property or if it has no change notifier signal, or if the dest object does not have the specified slot .

bool QDeclarativeProperty.connectNotifySignal ( self , callable  dest )

Connects the property's change notifier signal to the specified 方法 dest object and returns true. Returns false if this metaproperty does not represent a regular Qt property or if it has no change notifier signal, or if the dest object does not have the specified 方法 .

bool QDeclarativeProperty.connectNotifySignal ( self , QObject   dest , int  方法 )

bool QDeclarativeProperty.hasNotifySignal ( self )

Returns true if the property has a change notifier signal, otherwise false.

int QDeclarativeProperty.index ( self )

Return the Qt metaobject index of the property.

bool QDeclarativeProperty.isDesignable ( self )

Returns true if the property is designable, otherwise false.

bool QDeclarativeProperty.isProperty ( self )

返回 true,若此 QDeclarativeProperty represents a regular Qt property.

bool QDeclarativeProperty.isResettable ( self )

Returns true if the property is resettable, otherwise false.

bool QDeclarativeProperty.isSignalProperty ( self )

返回 true,若此 QDeclarativeProperty represents a QML signal property.

bool QDeclarativeProperty.isValid ( self )

返回 true 若 QDeclarativeProperty refers to a valid property, otherwise false.

bool QDeclarativeProperty.isWritable ( self )

Returns true if the property is writable, otherwise false.

QMetaMethod QDeclarativeProperty.method ( self )

返回 QMetaMethod for this property if it is a SignalProperty , otherwise returns an invalid QMetaMethod .

QString QDeclarativeProperty.name ( self )

Return the name of this QML property.

bool QDeclarativeProperty.needsNotifySignal ( self )

Returns true if the property needs a change notifier signal for bindings to remain upto date, false otherwise.

Some properties, such as attached properties or those whose value never changes, do not require a change notifier.

QObject QDeclarativeProperty.object ( self )

返回 QDeclarativeProperty 's QObject .

QMetaProperty QDeclarativeProperty.property ( self )

返回 Qt property associated with this QML property.

int QDeclarativeProperty.propertyType ( self )

返回 QVariant type of the property, or QVariant.Invalid if the property has no QVariant 类型。

PropertyTypeCategory QDeclarativeProperty.propertyTypeCategory ( self )

Returns the property category.

str QDeclarativeProperty.propertyTypeName ( self )

Returns the type name of the property, or 0 if the property has no type name.

QVariant QDeclarativeProperty.read ( self )

Returns the property value.

QVariant QDeclarativeProperty.read ( QObject , QString)

返回 name property value of object . This method is equivalent to:

 QDeclarativeProperty p(object, name);
 p.read();
			

QVariant QDeclarativeProperty.read ( QObject , QString, QDeclarativeContext )

返回 name property value of object 使用 context ctxt . This method is equivalent to:

 QDeclarativeProperty p(object, name, context);
 p.read();
			

QVariant QDeclarativeProperty.read ( QObject , QString, QDeclarativeEngine )

返回 name property value of object 使用 environment for instantiating QML components that is provided by engine . . This method is equivalent to:

 QDeclarativeProperty p(object, name, engine);
 p.read();
			

bool QDeclarativeProperty.reset ( self )

Resets the property and returns true if the property is resettable. If the property is not resettable, nothing happens and false is returned.

Type QDeclarativeProperty.type ( self )

Returns the type of the property.

bool QDeclarativeProperty.write ( self , QVariant)

Sets the property value to value and returns true. Returns false if the property can't be set because the value is the wrong type, for example.

bool QDeclarativeProperty.write ( QObject , QString, QVariant)

写入 value name property of object . This method is equivalent to:

 QDeclarativeProperty p(object, name);
 p.write(value);
			

bool QDeclarativeProperty.write ( QObject , QString, QVariant, QDeclarativeContext )

写入 value name property of object 使用 context ctxt . This method is equivalent to:

 QDeclarativeProperty p(object, name, ctxt);
 p.write(value);
			

bool QDeclarativeProperty.write ( QObject , QString, QVariant, QDeclarativeEngine )

写入 value name property of object using the environment for instantiating QML components that is provided by engine . This method is equivalent to:

 QDeclarativeProperty p(object, name, engine);
 p.write(value);
			

bool QDeclarativeProperty.__eq__ ( self , QDeclarativeProperty )

int QDeclarativeProperty.__hash__ ( self )

bool QDeclarativeProperty.__ne__ ( self , QDeclarativeProperty )