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
Forum Updated to NodeBB v4.3 + New Features

QList change color of rectangle in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlc++rectanglecolor changeqlist
3 Posts 2 Posters 657 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 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
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on 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
      0
      • dheerendraD dheerendra

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

        T Offline
        T Offline
        TMJJ001
        wrote on 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

        • Login

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