×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    Question QML GridView: problems handling clicks [Partially solved]

    Hi, I'm going crazy trying to set up a menu using a GridView. Basically the problem I have is that I am unable to capture the clicks on the elements of my GridView. So I can not take any action on the application. Can anyone tell me what I have wrong with my code?

    Code:
    import QtQuick 1.0
    
    Rectangle {
        width: 360
        height: 640
    
        GridView {
            id: menuGridView
            width: 300
            height: 550
            anchors.margins: 5
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.top: appLabel.bottom
            anchors.bottom: parent.bottom
    
            cellHeight: 100; cellWidth: 120
    
            model: menuModel
            delegate: menuDelegate
    
            highlight: highlightBar
    
            focus: true
        }
    
        Component {
            id: highlightBar
            Rectangle {
                width: menuGridView.cellWidth
                height: menuGridView.cellHeight
                color: "lightsteelblue"
                radius: 5
                x: menuGridView.currentItem.x
                y: menuGridView.currentItem.y
            }
        }
    
        Component {
            id: menuDelegate
            Item {
                width: menuGridView.cellWidth; height: menuGridView.cellHeight
                Column {
                    anchors.fill: parent
                    Image { source: imgSrc; anchors.horizontalCenter: parent.horizontalCenter }
                    Text { text: name; anchors.horizontalCenter: parent.horizontalCenter }
                }
                MouseArea
                {
                    anchors.fill: parent
                    onClicked: action
                }
            }
        }
    
        ListModel {
            id: menuModel
            ListElement {
                imgSrc: "../img/newlist.png"
                name: "New List"
            }
            ListElement {
                imgSrc: "../img/config.png"
                name: "Config"
            }
            ListElement {
                imgSrc: "../img/help.png"
                name: "Help"
            }
            ListElement {
                imgSrc: "../img/exit.png"
                name: "Exit"
                action: "Qt.quit()"
            }
    
        }
    
        Text {
            id: appLabel
            width: parent.width
            text: "Blah blah blah..."
            anchors.left: parent.left
            anchors.leftMargin: 5
            anchors.topMargin: 5
            font.pixelSize: 40
        }
    
    }
    Thanks!
    Last edited by the_hammer; 2011-07-18 at 18:39. Reason: Partial solution found using "Flow positioning"

  2. #2
    Super Contributor
    Join Date
    Jul 2007
    Location
    Magnitogorsk, Russia
    Posts
    536

    Re: QML GridView: problems handling clicks [Partially solved]

    You can define your own onClicked handler as part of menuDelegate, e.g.:

    Code:
    MouseArea
                {
                    anchors.fill: parent
                    onClicked: { if(name == "Exit") Qt.quit() }
                }

Similar Threads

  1. How to call/load another QML file from QML ?
    By cadlg in forum [Archived] Qt Quick
    Replies: 5
    Last Post: 2011-07-28, 09:15
  2. QML GridView: problems handling clicks
    By the_hammer in forum [Archived] Qt Quick
    Replies: 3
    Last Post: 2011-07-26, 12:12
  3. QML gridView crahes
    By mots_g in forum [Archived] Qt Quick
    Replies: 2
    Last Post: 2011-06-07, 10:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×