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
Forum Update on Tuesday, May 27th 2025

refreshing Gridview components on button click

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 5 Posters 1.1k 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.
  • S Offline
    S Offline
    Sam_George
    wrote on 8 Oct 2018, 12:16 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??

    G 1 Reply Last reply 8 Oct 2018, 12:26
    0
    • S Sam_George
      8 Oct 2018, 12:16

      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??

      G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 8 Oct 2018, 12:26 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 8 Oct 2018, 12:43 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 8 Oct 2018, 14:34
        0
        • S Sam_George
          8 Oct 2018, 12:43
          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 8 Oct 2018, 14:34 last edited by Yaswanth 10 Aug 2018, 14:52
          #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

          O 1 Reply Last reply 8 Oct 2018, 14:51
          0
          • Y Yaswanth
            8 Oct 2018, 14:34

            @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

            O Offline
            O Offline
            ODБOï
            wrote on 8 Oct 2018, 14:51 last edited by ODБOï 10 Aug 2018, 14:51
            #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 8 Oct 2018, 14:53
            1
            • O ODБOï
              8 Oct 2018, 14:51

              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 8 Oct 2018, 14:53 last edited by
              #6

              @LeLev it was typo :-(

              1 Reply Last reply
              2
              • D Offline
                D Offline
                dheerendra
                Qt Champions 2022
                wrote on 10 Oct 2018, 15:01 last edited by dheerendra 10 Oct 2018, 15:14
                #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 11 Oct 2018, 06:37 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

                  1/8

                  8 Oct 2018, 12:16

                  • Login

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