3

Please, is it possible to access and change a property of a qml element from javascript function? I read that document.getElementById() should do the trick, but when I try that I get:

ReferenceError: document is not defined

Test.qml

import QtQuick 2.0
import QtQuick.Controls 1.2
import Test.js as JS 

Rectangle{
    id: rect
    color: "red"

    onClicked: {
        JS.changeMe();
    }
}

Test.js

function changeMe(){
   //change the color of element "rect"
   //document.getElementById("rect")
}
miro
  • 809
  • 10
  • 25

1 Answers1

1

this worked:

Rectangle{
    id: rect
    color: "red"

    onClicked: {
        JS.changeMe(rect);
    }
}

function changeMe(rect){
   rect.color = "yellow";
}
miro
  • 809
  • 10
  • 25