PySide6.QtQml.QQmlProperty¶
- class QQmlProperty¶
- The - QQmlPropertyclass abstracts accessing properties on objects created from QML. More…- Synopsis¶- Properties¶- Methods¶- def - __init__()
- def - index()
- def - isBindable()
- def - isDesignable()
- def - isProperty()
- def - isResettable()
- def - isValid()
- def - isWritable()
- def - method()
- def - name()
- def - object()
- def - __eq__()
- def - property()
- def - propertyType()
- def - read()
- def - reset()
- def - swap()
- def - type()
- def - write()
 - Static functions¶- Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- 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 - QQmlPropertyclass that simplifies some of their natural complexity.- Unlike QMetaProperty which represents a property on a class type, - QQmlPropertyencapsulates a property on a specific object instance. To read a property’s value, programmers create a- QQmlPropertyinstance and call the- read()method. Likewise to write a property value the- write()method is used.- For example, for the following QML code: - The Text object’s properties could be accessed using - QQmlProperty, like this:- #include <QQmlProperty> #include <QGraphicsObject> ... QQuickView view(QUrl::fromLocalFile("MyItem.qml")); QQmlProperty 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(); - class PropertyTypeCategory¶
- This enum specifies a category of QML property. - Constant - Description - QQmlProperty.InvalidCategory - The property is invalid, or is a signal property. - QQmlProperty.List - The property is a - QQmlListPropertylist property- QQmlProperty.Object - The property is a QObject derived type pointer - QQmlProperty.Normal - The property is a normal value property. 
 - class Type¶
- This enum specifies a type of QML property. - Constant - Description - QQmlProperty.Invalid - The property is invalid. - QQmlProperty.Property - The property is a regular Qt property. - QQmlProperty.SignalProperty - The property is a signal property. 
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property nameᅟ: str¶
 - Access functions:
 - Access functions:
 - __init__()¶
 - Create an invalid - QQmlProperty.- __init__(obj)
- Parameters:
- obj – - QObject
 
 - Creates a - QQmlPropertyfor the default property of- obj. If there is no default property, an invalid- QQmlPropertywill be created.- __init__(other)
- Parameters:
- other – - QQmlProperty
 
 - Create a copy of - other.- __init__(obj, ctxt)
- Parameters:
- obj – - QObject
- ctxt – - QQmlContext
 
 
 - Creates a - QQmlPropertyfor the default property of- objusing the- context- ctxt. If there is no default property, an invalid- QQmlPropertywill be created.- __init__(obj, engine)
- Parameters:
- obj – - QObject
- engine – - QQmlEngine
 
 
 - Creates a - QQmlPropertyfor the default property of- objusing the environment for instantiating QML components that is provided by- engine. If there is no default property, an invalid- QQmlPropertywill be created.- __init__(obj, name)
- Parameters:
- obj – - QObject
- name – str 
 
 
 - Creates a - QQmlPropertyfor the property- nameof- obj.- __init__(obj, name, ctxt)
- Parameters:
- obj – - QObject
- name – str 
- ctxt – - QQmlContext
 
 
 - Creates a - QQmlPropertyfor the property- nameof- objusing the- context- ctxt.- Creating a - QQmlPropertywithout a context will render some properties - like attached properties - inaccessible.- __init__(obj, name, engine)
- Parameters:
- obj – - QObject
- name – str 
- engine – - QQmlEngine
 
 
 - Creates a - QQmlPropertyfor the property- nameof- objusing the environment for instantiating QML components that is provided by- engine.- Connects the property’s change notifier signal to the specified - slotof the- destobject 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- destobject does not have the specified- slot.- Note - slotshould be passed using the SLOT() macro so it is correctly identified.- connectNotifySignal(dest, method)
- Parameters:
- dest – - QObject
- method – int 
 
- Return type:
- bool 
 
 - Connects the property’s change notifier signal to the specified - methodof the- destobject 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- destobject does not have the specified- method.- hasNotifySignal()¶
- Return type:
- bool 
 
 - Returns true if the property has a change notifier signal, otherwise false. - index()¶
- Return type:
- int 
 
 - Return the Qt metaobject index of the property. - isBindable()¶
- Return type:
- bool 
 
 - isDesignable()¶
- Return type:
- bool 
 
 - Returns true if the property is designable, otherwise false. - isProperty()¶
- Return type:
- bool 
 
 - Returns true if this - QQmlPropertyrepresents a regular Qt property.- isResettable()¶
- Return type:
- bool 
 
 - Returns true if the property is resettable, otherwise false. - isSignalProperty()¶
- Return type:
- bool 
 
 - Returns true if this - QQmlPropertyrepresents a QML signal property.- isValid()¶
- Return type:
- bool 
 
 - Returns true if the - QQmlPropertyrefers to a valid property, otherwise false.- isWritable()¶
- Return type:
- bool 
 
 - Returns true if the property is writable, otherwise false. - method()¶
- Return type:
 
 - Return the QMetaMethod for this property if it is a - SignalProperty, otherwise returns an invalid QMetaMethod.- name()¶
- Return type:
- str 
 
 - Return the name of this QML property. - Getter of property - nameᅟ.- needsNotifySignal()¶
- Return type:
- bool 
 
 - 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. - Returns the - QQmlProperty‘s QObject.- Getter of property - objectᅟ.- __eq__(other)¶
- Parameters:
- other – - QQmlProperty
- Return type:
- bool 
 
 - Returns true if - otherand this- QQmlPropertyrepresent the same property.- property()¶
- Return type:
 
 - Returns the Qt property associated with this QML property. - Returns the metatype of the property. - See also - propertyType()¶
- Return type:
- int 
 
 - Returns the metatype id of the property, or QMetaType::UnknownType if the property has no metatype. - See also - propertyTypeCategory()¶
- Return type:
 
 - Returns the property category. - propertyTypeName()¶
- Return type:
- str 
 
 - Returns the type name of the property, or 0 if the property has no type name. - read()¶
- Return type:
- object 
 
 - Returns the property value. - static read(object, name)
- Parameters:
- object – - QObject
- name – str 
 
- Return type:
- object 
 
 - Return the - nameproperty value of- object. This method is equivalent to:- QQmlProperty p(object, name); p.read(); - static read(object, name, ctxt)
- Parameters:
- object – - QObject
- name – str 
- ctxt – - QQmlContext
 
- Return type:
- object 
 
 - Return the - nameproperty value of- objectusing the- context- ctxt. This method is equivalent to:- QQmlProperty p(object, name, context); p.read(); - static read(object, name, engine)
- Parameters:
- object – - QObject
- name – str 
- engine – - QQmlEngine
 
- Return type:
- object 
 
 - Return the - nameproperty value of- objectusing the environment for instantiating QML components that is provided by- engine. . This method is equivalent to:- QQmlProperty p(object, name, engine); p.read(); - reset()¶
- Return type:
- bool 
 
 - Resets the property and returns true if the property is resettable. If the property is not resettable, nothing happens and false is returned. - swap(other)¶
- Parameters:
- other – - QQmlProperty
 
 - Returns the type of the property. - write(value)¶
- Parameters:
- value – object 
- Return type:
- bool 
 
 - Sets the property value to - value. Returns- trueon success, or- falseif the property can’t be set because the- valueis the wrong type, for example.- static write(object, name, value)
- Parameters:
- object – - QObject
- name – str 
- value – object 
 
- Return type:
- bool 
 
 - Writes - valueto the- nameproperty of- object. This method is equivalent to:- QQmlProperty p(object, name); p.write(value); - Returns - trueon success,- falseotherwise.- static write(object, name, value, ctxt)
- Parameters:
- object – - QObject
- name – str 
- value – object 
- ctxt – - QQmlContext
 
- Return type:
- bool 
 
 - Writes - valueto the- nameproperty of- objectusing the- context- ctxt. This method is equivalent to:- QQmlProperty p(object, name, ctxt); p.write(value); - Returns - trueon success,- falseotherwise.- static write(object, name, value, engine)
- Parameters:
- object – - QObject
- name – str 
- value – object 
- engine – - QQmlEngine
 
- Return type:
- bool 
 
 - Writes - valueto the- nameproperty of- objectusing the environment for instantiating QML components that is provided by- engine. This method is equivalent to:- QQmlProperty p(object, name, engine); p.write(value); - Returns - trueon success,- falseotherwise.