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. Access to item inside a GridView

Access to item inside a GridView

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

    I have a gridview with images. When an image is clicked a dialog appears, which is defined outside of the gridview. When the dialog is clicked, the state of the previously clicked image should be changed. How can I achieve this?

    Example code:

    @
    Rectangle {

    ListModel {
    id: gridModel
    ListElement{
    imageSource: ""
    }
    }

    Component {
    id: gridDelegate

    Item{
    Image {
    source: imageSource
    MouseArea{
    anchors.fill: parent
    onClicked: dialog.visible = true
    }
    }
    }
    }

    GridView {
    model: gridModel
    delegate: gridDelegate
    }

    Rectangle {
    id: dialog
    Button {
    onClick: {
    //change state of clicked image here//
    dialog.visible = false;
    }
    }
    }
    }
    @

    Somehow the spaces are messed up in the code exampe :/

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vincent007
      wrote on last edited by
      #2

      @
      Rectangle {
      property int selectedIndex: -1

      ListModel {
       id: gridModel
       ListElement{
        imageSource: ""
       }
      }
       
      Component {
       id: gridDelegate
       
       Item{
        Image {
         source: imageSource
         MouseArea{
          anchors.fill: parent
          onClicked: dialog.visible = true
          selectedIndex = index
         }
        }
        function changeState() {
        }
       }
      }
       
      GridView {
          id: gridView
          model: gridModel
          delegate: gridDelegate
      }
       
      Rectangle {
       id: dialog
       Button {
        onClick: {
          //change state of clicked image here//
          dialog.visible = false;
          gridView.children[selectedIndex].changeState()
         }
       }
      }
      }
      

      @

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerMas
        wrote on last edited by
        #3

        Thx. Always feeling dumb, when a solution is that simple ;)

        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