How to modify QML dynamic objects from JavaScript

Zhas Nurushev

I have QML file which describes button(moduleButton.qml):

import QtQuick 2.0
Rectangle {
    id: button;
    width: 100; height: 20
    Text {
        id: buttonText;
        text: "Hello World";
    }
}

From other QML form I load this button via Qt.createComponent method:

var moduleButton = Qt.createComponent("moduleButton.qml");
moduleButton.createObject(mainRect);

I tried to set/get width of moduleButton:

moduleButton.width = 30;

But received following error: Cannot assign to non-existent property "width"

How to access dynamic object attributes and child elements?

P.S. Qt.createQmlObject method perfectly works, but I need to load QML from file, not from string.

Armaghast

createObject() returns the new object. Your code should look like this:

var moduleButton = Qt.createComponent("moduleButton.qml");
var myButton = moduleButton.createObject(mainRect);

myButton.width = 40

The moduleButton is a component (a factory), used to instantiate the item.

Documentation: http://qt-project.org/doc/qt-5/qtqml-javascript-dynamicobjectcreation.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to modify QML dynamic objects from JavaScript

From Dev

How to create/destroy dynamic objects after the same event in QML?

From Dev

How do I permanently delete objects from a QML canvas?

From Java

Reactjs: how to modify dynamic child component state or props from parent?

From Dev

Javascript dynamic nested objects

From Dev

How to animate multiple objects in qml

From Dev

How to call a Javascript function defined in a QML file from another QML file?

From Dev

How to call a Javascript function defined in a QML file from another QML file?

From Dev

QML - How to create QML Components properties so they can be set from JavaScript?

From Dev

QML: 'Steal' events from dynamic MouseArea

From Dev

Dynamic Linq - How to select parent objects from child properties

From Dev

Why is the creation of dynamic qml objects so slow, and what reasonable alternatives are there?

From Dev

Why is the creation of dynamic qml objects so slow, and what reasonable alternatives are there?

From Dev

Accessing QML objects from C++

From Dev

Add objects to QML layout from C++

From Dev

Type of objects passed from Qml to C++

From Dev

access qml element from javascript

From Dev

How to get JavaScript Objects with inheritance from JSON?

From Dev

how to calculate new data from objects in javascript

From Dev

Javascript Objects (dynamic attribute names)

From Dev

QML , How to Access Element from Another qml

From Dev

How to remove unmatched objects from array of objects using javascript or lodash

From Dev

javascript How to get an objects value from an array full of objects?

From Dev

How to modify a URL in Javascript

From Dev

How to modify "this" in javascript

From Dev

How to Add Dynamic Data to a QML Table

From Dev

How to change property of other objects in QML

From Dev

Javascript: Modify an object from a pointer

From Dev

How to modify dynamic query in SQL Server?

Related Related

  1. 1

    How to modify QML dynamic objects from JavaScript

  2. 2

    How to create/destroy dynamic objects after the same event in QML?

  3. 3

    How do I permanently delete objects from a QML canvas?

  4. 4

    Reactjs: how to modify dynamic child component state or props from parent?

  5. 5

    Javascript dynamic nested objects

  6. 6

    How to animate multiple objects in qml

  7. 7

    How to call a Javascript function defined in a QML file from another QML file?

  8. 8

    How to call a Javascript function defined in a QML file from another QML file?

  9. 9

    QML - How to create QML Components properties so they can be set from JavaScript?

  10. 10

    QML: 'Steal' events from dynamic MouseArea

  11. 11

    Dynamic Linq - How to select parent objects from child properties

  12. 12

    Why is the creation of dynamic qml objects so slow, and what reasonable alternatives are there?

  13. 13

    Why is the creation of dynamic qml objects so slow, and what reasonable alternatives are there?

  14. 14

    Accessing QML objects from C++

  15. 15

    Add objects to QML layout from C++

  16. 16

    Type of objects passed from Qml to C++

  17. 17

    access qml element from javascript

  18. 18

    How to get JavaScript Objects with inheritance from JSON?

  19. 19

    how to calculate new data from objects in javascript

  20. 20

    Javascript Objects (dynamic attribute names)

  21. 21

    QML , How to Access Element from Another qml

  22. 22

    How to remove unmatched objects from array of objects using javascript or lodash

  23. 23

    javascript How to get an objects value from an array full of objects?

  24. 24

    How to modify a URL in Javascript

  25. 25

    How to modify "this" in javascript

  26. 26

    How to Add Dynamic Data to a QML Table

  27. 27

    How to change property of other objects in QML

  28. 28

    Javascript: Modify an object from a pointer

  29. 29

    How to modify dynamic query in SQL Server?

HotTag

Archive