Reference a QML object id from a JavaScript function
-
wrote on 13 Jan 2021, 22:30 last edited by biskero
I have a QML object with an id and I want to change some color inside the QML object from a function.
What is the syntax?Rectangle {
id: rect
.......
}
Something like this:
function changeColor() {
.....
rect.color = "black"
}Can't figure out how is done, any suggestions?
thx -
I have a QML object with an id and I want to change some color inside the QML object from a function.
What is the syntax?Rectangle {
id: rect
.......
}
Something like this:
function changeColor() {
.....
rect.color = "black"
}Can't figure out how is done, any suggestions?
thx -
I have a QML object with an id and I want to change some color inside the QML object from a function.
What is the syntax?Rectangle {
id: rect
.......
}
Something like this:
function changeColor() {
.....
rect.color = "black"
}Can't figure out how is done, any suggestions?
thxwrote on 14 Jan 2021, 06:42 last edited by@biskero said in Reference a QML object id from a JavaScript function:
Can't figure out how is done, any suggestions?
Why do you say this does not work? You only have to ensure that the is in the scope of your function
==> https://doc.qt.io/qt-5/qtqml-documents-scope.html -
wrote on 14 Jan 2021, 12:20 last edited by biskero
I get "Unreachable (M28)" message at the line where I do rect.color = "black";
This happens if I keep the function within the Rectangle Object or outside.
That's why I am confused.Just to clarify what I am trying to do.
I have a slider that changes the color of another object.
Once I change the color, I store that color RGB in a db.
Once I restart the app, I want to set the slider to the stored RGB color, and the slider to the same RGB value.So I have the function, called rgbToHsl, that gets as input the HEX value of color, it converts to HSL, and returns the value to the slider.
But some how when I do reference the slider and I assign the value, I get that error.
The slider has property color colorValue, so I am trying to set the colorValue likerect.color = colorValue
2/4