QQmlProperty#

The QQmlProperty class abstracts accessing properties on objects created from QML. More

Synopsis#

Properties#

Functions#

Static functions#

  • def read (arg__1, arg__2)

  • def read (arg__1, arg__2, arg__3)

  • def read (arg__1, arg__2, arg__3)

  • def write (arg__1, arg__2, arg__3)

  • def write (arg__1, arg__2, arg__3, arg__4)

  • def write (arg__1, arg__2, arg__3, arg__4)

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 QQmlProperty class that simplifies some of their natural complexity.

Unlike QMetaProperty which represents a property on a class type, QQmlProperty encapsulates a property on a specific object instance. To read a property’s value, programmers create a QQmlProperty instance 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 PySide6.QtQml.QQmlProperty#

PySide6.QtQml.QQmlProperty(arg__1)

PySide6.QtQml.QQmlProperty(arg__1, arg__2)

PySide6.QtQml.QQmlProperty(arg__1, arg__2)

PySide6.QtQml.QQmlProperty(arg__1, arg__2)

PySide6.QtQml.QQmlProperty(arg__1, arg__2, arg__3)

PySide6.QtQml.QQmlProperty(arg__1, arg__2, arg__3)

PySide6.QtQml.QQmlProperty(arg__1)

Parameters:

Create an invalid QQmlProperty .

Creates a QQmlProperty for the default property of obj. If there is no default property, an invalid QQmlProperty will be created.

Creates a QQmlProperty for the default property of obj using the context ctxt. If there is no default property, an invalid QQmlProperty will be created.

Creates a QQmlProperty for the default property of obj using the environment for instantiating QML components that is provided by engine. If there is no default property, an invalid QQmlProperty will be created.

Creates a QQmlProperty for the property name of obj.

Creates a QQmlProperty for the property name of obj using the context ctxt.

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

Creates a QQmlProperty for the property name of obj using the environment for instantiating QML components that is provided by engine.

Create a copy of other.

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.QtQml.QQmlProperty.name: str#
Access functions:
property PᅟySide6.QtQml.QQmlProperty.object: PySide6.QtCore.QObject#
Access functions:
PySide6.QtQml.QQmlProperty.QmlIsAnonymous#
PySide6.QtQml.QQmlProperty.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 QQmlListProperty list property

QQmlProperty.Object

The property is a QObject derived type pointer

QQmlProperty.Normal

The property is a normal value property.

PySide6.QtQml.QQmlProperty.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.

PySide6.QtQml.QQmlProperty.connectNotifySignal(dest, method)#
Parameters:
Return type:

bool

Connects the property’s change notifier signal to the specified method of the 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 method.

PySide6.QtQml.QQmlProperty.connectNotifySignal(dest, slot)
Parameters:
Return type:

bool

Connects the property’s change notifier signal to the specified slot of the 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.

Note

slot should be passed using the SLOT() macro so it is correctly identified.

PySide6.QtQml.QQmlProperty.hasNotifySignal()#
Return type:

bool

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

PySide6.QtQml.QQmlProperty.index()#
Return type:

int

Return the Qt metaobject index of the property.

PySide6.QtQml.QQmlProperty.isBindable()#
Return type:

bool

PySide6.QtQml.QQmlProperty.isDesignable()#
Return type:

bool

Returns true if the property is designable, otherwise false.

PySide6.QtQml.QQmlProperty.isProperty()#
Return type:

bool

Returns true if this QQmlProperty represents a regular Qt property.

PySide6.QtQml.QQmlProperty.isResettable()#
Return type:

bool

Returns true if the property is resettable, otherwise false.

PySide6.QtQml.QQmlProperty.isSignalProperty()#
Return type:

bool

Returns true if this QQmlProperty represents a QML signal property.

PySide6.QtQml.QQmlProperty.isValid()#
Return type:

bool

Returns true if the QQmlProperty refers to a valid property, otherwise false.

PySide6.QtQml.QQmlProperty.isWritable()#
Return type:

bool

Returns true if the property is writable, otherwise false.

PySide6.QtQml.QQmlProperty.method()#
Return type:

PySide6.QtCore.QMetaMethod

Return the QMetaMethod for this property if it is a SignalProperty , otherwise returns an invalid QMetaMethod.

PySide6.QtQml.QQmlProperty.name()#
Return type:

str

Return the name of this QML property.

Getter of property name .

PySide6.QtQml.QQmlProperty.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.

PySide6.QtQml.QQmlProperty.object()#
Return type:

PySide6.QtCore.QObject

Returns the QQmlProperty ‘s QObject.

Getter of property object .

PySide6.QtQml.QQmlProperty.__eq__(arg__1)#
Parameters:

arg__1PySide6.QtQml.QQmlProperty

Return type:

bool

Returns true if other and this QQmlProperty represent the same property.

PySide6.QtQml.QQmlProperty.property()#
Return type:

PySide6.QtCore.QMetaProperty

Returns the Qt property associated with this QML property.

PySide6.QtQml.QQmlProperty.propertyMetaType()#
Return type:

PySide6.QtCore.QMetaType

Returns the metatype of the property.

See also

propertyType

PySide6.QtQml.QQmlProperty.propertyType()#
Return type:

int

Returns the metatype id of the property, or QMetaType::UnknownType if the property has no metatype.

See also

propertyMetaType

PySide6.QtQml.QQmlProperty.propertyTypeCategory()#
Return type:

PropertyTypeCategory

Returns the property category.

PySide6.QtQml.QQmlProperty.propertyTypeName()#
Return type:

str

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

PySide6.QtQml.QQmlProperty.read()#
Return type:

object

Returns the property value.

static PySide6.QtQml.QQmlProperty.read(arg__1, arg__2)
Parameters:
Return type:

object

Return the name property value of object. This method is equivalent to:

QQmlProperty p(object, name);
p.read();
static PySide6.QtQml.QQmlProperty.read(arg__1, arg__2, arg__3)
Parameters:
Return type:

object

Return the name property value of object using the context ctxt. This method is equivalent to:

QQmlProperty p(object, name, context);
p.read();
static PySide6.QtQml.QQmlProperty.read(arg__1, arg__2, arg__3)
Parameters:
Return type:

object

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

QQmlProperty p(object, name, engine);
p.read();
PySide6.QtQml.QQmlProperty.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.

PySide6.QtQml.QQmlProperty.swap(other)#
Parameters:

otherPySide6.QtQml.QQmlProperty

PySide6.QtQml.QQmlProperty.type()#
Return type:

Type

Returns the type of the property.

static PySide6.QtQml.QQmlProperty.write(arg__1, arg__2, arg__3)#
Parameters:
Return type:

bool

Writes value to the name property of object. This method is equivalent to:

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

Returns true on success, false otherwise.

static PySide6.QtQml.QQmlProperty.write(arg__1, arg__2, arg__3, arg__4)
Parameters:
Return type:

bool

Writes value to the name property of object using the context ctxt. This method is equivalent to:

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

Returns true on success, false otherwise.

static PySide6.QtQml.QQmlProperty.write(arg__1, arg__2, arg__3, arg__4)
Parameters:
Return type:

bool

Writes value to the name property of object using 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 true on success, false otherwise.

PySide6.QtQml.QQmlProperty.write(arg__1)
Parameters:

arg__1 – object

Return type:

bool

Sets the property value to value. Returns true on success, or false if the property can’t be set because the value is the wrong type, for example.