Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QList change color of rectangle in QML
QtWS25 Last Chance

QList change color of rectangle in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlc++rectanglecolor changeqlist
3 Posts 2 Posters 624 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TMJJ001
    wrote on 20 Apr 2022, 05:58 last edited by
    #1

    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

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 20 Apr 2022, 07:22 last edited by
      #2

      Your code should work as it. Do you see any issue ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      T 1 Reply Last reply 20 Apr 2022, 10:39
      0
      • D dheerendra
        20 Apr 2022, 07:22

        Your code should work as it. Do you see any issue ?

        T Offline
        T Offline
        TMJJ001
        wrote on 20 Apr 2022, 10:39 last edited by
        #3

        @dheerendra thsnls for your reponse.
        But how do I get the onChanged of param to run the if statements?
        Thanks

        1 Reply Last reply
        0

        2/3

        20 Apr 2022, 07:22

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved