×

Discussion Board

Results 1 to 4 of 4
  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
    Nokia Developer Champion
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

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

    I think your action should be between {} and not "". so:
    ListElement {
    ...
    action: {Qt.quit()}
    }

  3. #3
    Nokia Developer Champion
    Join Date
    Jul 2007
    Location
    Magnitogorsk, Russia
    Posts
    536

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


  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    5

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

    Quote Originally Posted by njzk2 View Post
    I think your action should be between {} and not "". so:
    ListElement {
    ...
    action: {Qt.quit()}
    }
    Thanks! but that doesn''t work because ListElement not support such literals.

    Quote Originally Posted by Den123 View Post
    Also thanks to you! Just read your answer, it works OK (catches clicks!) but the highlighter is allways "over" first element.

    I think i will continue with my custom GridView using a flow layout with my custom button.

    Thanks anyway.

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 crahes
    By mots_g in forum [Archived] Qt Quick
    Replies: 2
    Last Post: 2011-06-07, 10:01
  3. How to adjust Font in Gridview?
    By chirag_cel in forum Symbian
    Replies: 8
    Last Post: 2007-12-07, 04:41
  4. Key Clicks
    By smb101 in forum Mobile Java General
    Replies: 1
    Last Post: 2006-04-23, 23:14

Posting Permissions

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