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. refreshing Gridview components on button click
QtWS25 Last Chance

refreshing Gridview components on button click

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 5 Posters 1.1k 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.
  • S Offline
    S Offline
    Sam_George
    wrote on last edited by
    #1

    Hi,

    I have a gridview which has 30-40 components. And i have a button on the screen, which when pressed changes the image source of the components. But the components which are visible on the gridview do not alter but as i scroll down, i find that the components which were not visible previously have altered image. And on scrolling back to previous position, the components which were not refreshed are now altered. In short the gridview components do not alter spontaneously. Any Help??

    GrecKoG 1 Reply Last reply
    0
    • S Sam_George

      Hi,

      I have a gridview which has 30-40 components. And i have a button on the screen, which when pressed changes the image source of the components. But the components which are visible on the gridview do not alter but as i scroll down, i find that the components which were not visible previously have altered image. And on scrolling back to previous position, the components which were not refreshed are now altered. In short the gridview components do not alter spontaneously. Any Help??

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      How do you actually change the image source of the components ?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam_George
        wrote on last edited by
        #3
        Component
        {
        Image {
                                    id:folderImg
                                    width:140
                                    height:175
                                    source: selectAllFlag?"Assets/RecBtn2.png":"Assets/RecBtn1.png";
        
                                    anchors.horizontalCenter: parent.horizontalCenter
           }
        }
        
        where selectAllFlag is the status of the button.
        
        Y 1 Reply Last reply
        0
        • S Sam_George
          Component
          {
          Image {
                                      id:folderImg
                                      width:140
                                      height:175
                                      source: selectAllFlag?"Assets/RecBtn2.png":"Assets/RecBtn1.png";
          
                                      anchors.horizontalCenter: parent.horizontalCenter
             }
          }
          
          where selectAllFlag is the status of the button.
          
          Y Offline
          Y Offline
          Yaswanth
          wrote on last edited by Yaswanth
          #4

          @Sam_George just to understand, you can add mousearea to image and print the value of selectAllFlag on click. If selectAllFlag value fine add a handler for selectAllFlag in delegate and set the source of the image on it. Like onSelectAllFlagChanged:
          selectAllFlag ? source = second : source= first

          ODБOïO 1 Reply Last reply
          0
          • Y Yaswanth

            @Sam_George just to understand, you can add mousearea to image and print the value of selectAllFlag on click. If selectAllFlag value fine add a handler for selectAllFlag in delegate and set the source of the image on it. Like onSelectAllFlagChanged:
            selectAllFlag ? source = second : source= first

            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by ODБOï
            #5

            hi

            @Yaswanth said in refreshing Gridview components on button click:

            Like onSelectAllFlagChanged:
            selectAllFlag ? source : second : first

            conditionnal operator will not work like this (use "=" for assign, not ":" ), correct verion is

            onSelectAllFlagChanged: selectAllFlag ? source= second : source = first
            
            Y 1 Reply Last reply
            1
            • ODБOïO ODБOï

              hi

              @Yaswanth said in refreshing Gridview components on button click:

              Like onSelectAllFlagChanged:
              selectAllFlag ? source : second : first

              conditionnal operator will not work like this (use "=" for assign, not ":" ), correct verion is

              onSelectAllFlagChanged: selectAllFlag ? source= second : source = first
              
              Y Offline
              Y Offline
              Yaswanth
              wrote on last edited by
              #6

              @LeLev it was typo :-(

              1 Reply Last reply
              2
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by dheerendra
                #7

                Why are you changing the delegate directly ? You can change model. It should update the view. It is auto taken care.

                If you still would like to do what you wanted -
                Changing directly in component will not help. Delegate are individual objects and source is already set with your image. If you change in component, it will not change source of already created objects. So when you scroll down, new delegate objects are getting created. Hence you will see the new image. When you scroll back, old delegate objects would have been destroyed. So it is creating new objects. Hence you will see new images. If you want to change the existing delegate object, get the reference of all the child objects. All the delegate objects are parented to contentItem. So get all the children of contentItem and update them.

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

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  Sam_George
                  wrote on last edited by
                  #8

                  Thank you all,

                  It worked. I made one extra property in Component Item which gets updated whenever the selectAllFlag status changes. So I added a handler for this new variable inside the Component Item which on change changes the source of the image. Thank you all once again..

                  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