diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-22 14:15:37 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-23 14:01:19 +0200 |
commit | c0674262fd7e859a8002e6e850b6ec0a4162b456 (patch) | |
tree | c298748c9804b7657cf704ac951bccffafc8c3a3 | |
parent | 9f09e1dda0f167432110a22db6f9a5accf800734 (diff) |
Documentation: Add QtQml.ListProperty
Pick-to: 6.7
Task-number: PYSIDE-2698
Change-Id: If9b9af49bb351fcb4e2355277ff84bd0936b5033
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
3 files changed, 34 insertions, 9 deletions
diff --git a/examples/qml/tutorials/extending-qml-advanced/properties/doc/properties.rst b/examples/qml/tutorials/extending-qml-advanced/properties/doc/properties.rst index 9337ad2ab..16924cdcd 100644 --- a/examples/qml/tutorials/extending-qml-advanced/properties/doc/properties.rst +++ b/examples/qml/tutorials/extending-qml-advanced/properties/doc/properties.rst @@ -75,11 +75,11 @@ The class contains a member to store the celebrant object, and also a list member storing the Person instances. In QML, the type of a list properties - and the guests property is a list of -people - are all of type ListProperty. ListProperty is simple value -type that contains a set of functions. QML calls these functions -whenever it needs to read from, write to or otherwise interact with -the list. In addition to concrete lists like the people list used in this -example, the use of QQmlListProperty allows for "virtual lists" and other advanced +people - are all of type :class:`~PySide6.QtQml.ListProperty`. +``ListProperty`` is a simple value type that contains a set of functions. +QML calls these functions whenever it needs to read from, write to or otherwise +interact with the list. In addition to concrete lists like the people list used in this +example, the use of ``ListProperty`` allows for "virtual lists" and other advanced scenarios. Running the Example diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/doc/chapter5-listproperties.rst b/examples/qml/tutorials/extending-qml/chapter5-listproperties/doc/chapter5-listproperties.rst index 90cb41107..a98f18c81 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/doc/chapter5-listproperties.rst +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/doc/chapter5-listproperties.rst @@ -15,8 +15,9 @@ have a ``slices`` property that accepts a list of ``PieSlice`` items: :lines: 4-32 To do this, we replace the ``pieSlice`` property in ``PieChart`` with a -``slices`` property, declared as a class variable of the ``QQmlListProperty`` -type. The ``QQmlListProperty`` class enables the creation of list properties in +``slices`` property, declared as a class variable of the +:class:`~PySide6.QtQml.ListProperty` type. +The ``ListProperty`` class enables the creation of list properties in QML extensions. We replace the ``pieSlice()`` function with a ``slices()`` function that returns a list of slices, and add an internal ``appendSlice()`` function (discussed below). We also use a list to store the internal list of @@ -31,13 +32,13 @@ slices as ``_slices``: :lines: 75-79 Although the ``slices`` property does not have an associated setter, it is -still modifiable because of the way ``QQmlListProperty`` works. We indicate +still modifiable because of the way ``ListProperty`` works. We indicate that the internal ``PieChart.appendSlice()`` function is to be called whenever a request is made from QML to add items to the list. The ``appendSlice()`` function simply sets the parent item as before, and adds the new item to the ``_slices`` list. As you can see, the append function for -a ``QQmlListProperty`` is called with two arguments: the list property, and the +a ``ListProperty`` is called with two arguments: the list property, and the item that is to be appended. The ``PieSlice`` class has also been modified to include ``fromAngle`` and diff --git a/sources/pyside6/doc/extras/QtQml.ListProperty.rst b/sources/pyside6/doc/extras/QtQml.ListProperty.rst new file mode 100644 index 000000000..eaa580c68 --- /dev/null +++ b/sources/pyside6/doc/extras/QtQml.ListProperty.rst @@ -0,0 +1,24 @@ +.. currentmodule:: PySide6.QtQml +.. py:class:: ListProperty + + The ``ListProperty`` class allows applications to expose list-like properties of + :class:`~PySide6.QtCore.QObject`-derived classes to QML. + The usage is shown in the :ref:`qml-object-and-list-property-types-example` + and the :ref:`qml-chapter5-listproperties` example. + + .. py:method:: __init__(type, append, count=None, at=None, clear=None, removeLast=None, doc="", notify=None, designable=True, scriptable=True, stored=True, user=False, constant=False, final=False) + + :param type type: Element type + :param callable append: A function to append an item + :param callable count: A function returning the list count + :param callable at: A function returning the item at an index + :param callable clear: A function to clear the list + :param removeLast: A function to remove the last item + :param str doc: Doc string + :param Signal notify: A signal emitted when a change occurs + :param bool designable: Not used in QML + :param bool scriptable: Not used in QML + :param bool stored: Whether the property is stored + :param bool user: Not used in QML + :param bool constant: Whether the property is constant + :param bool final: Whether the property is final |