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. GridView : change state of an item

GridView : change state of an item

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 5.6k 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.
  • Q Offline
    Q Offline
    qtnext
    wrote on last edited by
    #1

    Hi,

    I wants to display image in a gridview. When I click on an image delegate, I change state (change size image, ....). I wants to be able to reset previous selected image when I click outside of the item (when I click on an empty area or when I click on another image). I don't know how can I do this ?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Rather than directly setting the state when clicking, you can set the currentIndex of the GridView to the index of the item you've clicked (onClicked: view.currentIndex = index), and use the isCurrentItem attached property to change the state (when: delegateId.GridView.isCurrentItem). That will make sure that only one item in the GridView ever looks selected.

      For clicking in an empty area, you could try filling all the extra space with a MouseArea (e.g. behind the GridView), and setting the currentIndex to -1 when clicked to clear the selection. This is something I don't think that we handle very well right now, but that should hopefully improve in future releases. Others might have ideas for a better approach.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtnext
        wrote on last edited by
        #3

        thanks for your help. It works now for select an item (and return the previous item to default state), but it don't works for the mousearea :

        • it seems that set currentIndex to -1 do nothing

        • if i do
          @
          MouseArea{
          z:10;
          anchors.fill:parent;
          onClicked :grid_view.currentIndex=4;
          }
          @
          with z==10 for exemple, it catch all mouse events, If I do z=-1 (behind the gridview) gridview catch all mouse events... so it don't work

        [edit: added @ tag / $chetankjain]

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #4

          hi qtnext, better to format code snips using the @ tag, easier to read

          1 Reply Last reply
          0
          • A Offline
            A Offline
            anselmolsm
            wrote on last edited by
            #5

            @qtnext

            I wrote "an example":http://developer.qt.nokia.com/wiki/QML_gridview_mousearea_example based on what you described and on mbrasser's suggestion (comments and fixes are welcome =)

            You need to set the z order of the 'external' mouse area to put it behind the grid view. In the example the mouse area is declared before the GridView, so I did not set z.

            I think you are in the right way, just a small detail to make it work as expected =)

            Anselmo L. S. Melo (anselmolsm)

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qtnext
              wrote on last edited by
              #6

              I have tried what you have done in your sample (that exactly what I am trying to do) but it don't works (with or without z order) . It seems that grid view catch all mouse event

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mbrasser
                wrote on last edited by
                #7

                Hmm, you are right, it is more complicated if you want clicking the empty space within the grid to deselect. I've edited anselmolsm's example to show one way to support this, along with a note on why the fix works. Note that the fix uses an undocumented property (flickableChildren) in order to have the MouseArea become a child of the contentItem.

                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