QList change color of rectangle in QML
Unsolved
QML and Qt Quick
-
Dears,
I think I want to do something very simple, but it seems like I can not figure out how to do so.
I have a QList<bool> param variable with 31 values.Now when value 17 is true, I want to change the color of the rectangle in QML.
class BackendQml : public QObject { Q_OBJECT Q_PROPERTY(QList<bool> param READ param WRITE setParam NOTIFY paramChanged) public: explicit BackendQml(QObject *parent = nullptr); QList<bool> param() const{return m_param;} signals: void paramChanged(QList<bool> param); public slots: void setParam(QList<bool> param); private: QList<bool> m_param; }; #endif // BACKENDQML_H
Now in my qml file I want to do something like:
if(backendQml.param[17] == true) { rectangle.color = "red"; } else { rectangle.color = "blue"; }
Could somebody help me out with this?
Thanks in advance,
Kind regards -
Your code should work as it. Do you see any issue ?
-
@dheerendra thsnls for your reponse.
But how do I get the onChanged of param to run the if statements?
Thanks