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. updating visibility based on QVariantList
Forum Updated to NodeBB v4.3 + New Features

updating visibility based on QVariantList

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 781 Views 1 Watching
  • 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I'm trying to build on my learning from this earlier thread. In my C++, I have a property defined:

    private:
      QVariantList m_columnCapList;
    public:
      Q_PROPERTY( QVariantList columnCapStatus MEMBER m_columnCapList NOTIFY columnCapsUpdated)
    signals:
      void columnCapsUpdated(QVariantList columnCapsList);
    

    And a singleton of this class is properly exposed to QML, etc. I fill this list with boolean values. Each element corresponds to a rectangle in a QML view; I want the rectangle's visibility to be derived from the value in the list. Here's what I've tried so far:

    Repeater {
    	id: columnCaps
    	model: wellPlateColNames.length
    	Rectangle {
    		visible: issViewModel.columnCapStatus[index]
    		x: 100 + index + (100)
    		y: 100 + index + (100)
    		height: 50
    		width: 50
    		color: 'pink'
    	}
    }
    

    But this doesn't work. I've also tried the Connections type, without success. I figure I'm probably over-thinking this (as usual), so...what's the crisp-and-clean way to set the rectangles' visibilities based on C++ data?

    Thanks...

    J.HilkJ 1 Reply Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      I'm trying to build on my learning from this earlier thread. In my C++, I have a property defined:

      private:
        QVariantList m_columnCapList;
      public:
        Q_PROPERTY( QVariantList columnCapStatus MEMBER m_columnCapList NOTIFY columnCapsUpdated)
      signals:
        void columnCapsUpdated(QVariantList columnCapsList);
      

      And a singleton of this class is properly exposed to QML, etc. I fill this list with boolean values. Each element corresponds to a rectangle in a QML view; I want the rectangle's visibility to be derived from the value in the list. Here's what I've tried so far:

      Repeater {
      	id: columnCaps
      	model: wellPlateColNames.length
      	Rectangle {
      		visible: issViewModel.columnCapStatus[index]
      		x: 100 + index + (100)
      		y: 100 + index + (100)
      		height: 50
      		width: 50
      		color: 'pink'
      	}
      }
      

      But this doesn't work. I've also tried the Connections type, without success. I figure I'm probably over-thinking this (as usual), so...what's the crisp-and-clean way to set the rectangles' visibilities based on C++ data?

      Thanks...

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @mzimmers

      so...what's the crisp-and-clean way to set the rectangles' visibilities based on C++ data?

      probably:

      Repeater {
      	id: columnCaps
      	model: columnCapStatus
      	Rectangle {
      		visible: modelData
      		x: 100 + index + (100)
      		y: 100 + index + (100)
      		height: 50
      		width: 50
      		color: 'pink'
      	}
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        I'm getting an error at startup:

        ReferenceError: columnCapList is not defined
        

        I've renamed a few items, so I'm showing the definition again below:

          Q_PROPERTY( QVariantList columnCapList
                      MEMBER m_columnCapList
                      NOTIFY columnCapsUpdated)
          Q_INVOKABLE bool getColumnCapStatus(int index);
          QVariantList m_columnCapList;
        

        The QML:

        Repeater {
        	id: columnCaps
        	model: columnCapList
        
        	Rectangle {
        		visible: modelData
        		x: index + (50 * index)
        		y: index - (50 * index)
        		height: 50
        		width: 50
        		color: 'pink'
        	}
        

        Any idea what I'm doing wrong?

        J.HilkJ 1 Reply Last reply
        0
        • mzimmersM mzimmers

          I'm getting an error at startup:

          ReferenceError: columnCapList is not defined
          

          I've renamed a few items, so I'm showing the definition again below:

            Q_PROPERTY( QVariantList columnCapList
                        MEMBER m_columnCapList
                        NOTIFY columnCapsUpdated)
            Q_INVOKABLE bool getColumnCapStatus(int index);
            QVariantList m_columnCapList;
          

          The QML:

          Repeater {
          	id: columnCaps
          	model: columnCapList
          
          	Rectangle {
          		visible: modelData
          		x: index + (50 * index)
          		y: index - (50 * index)
          		height: 50
          		width: 50
          		color: 'pink'
          	}
          

          Any idea what I'm doing wrong?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @mzimmers can you show the singleton exposure to the JSEngine ?


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          mzimmersM 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @mzimmers can you show the singleton exposure to the JSEngine ?

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @J-Hilk this routine is called by a "master" exposure routine:

            void IssApi::ExportContextPropertiesToQml(QQmlEngine *engine) {
              engine->rootContext()->setContextProperty("issViewModel", this);
            ...
            
            J.HilkJ 1 Reply Last reply
            0
            • mzimmersM mzimmers

              @J-Hilk this routine is called by a "master" exposure routine:

              void IssApi::ExportContextPropertiesToQml(QQmlEngine *engine) {
                engine->rootContext()->setContextProperty("issViewModel", this);
              ...
              
              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by J.Hilk
              #6

              @mzimmers ok:

              so this should work than

              model: issViewModel.columnCapStatus
              

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              3
              • mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #7

                Oh, sheesh...I can't believe I forgot that. Thanks, J.Hilk.

                1 Reply Last reply
                1

                • Login

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