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
}
}
[/CODE]
Thanks!
Re: QML GridView: problems handling clicks [Partially solved]
I think your action should be between {} and not "". so:
ListElement {
...
action: {Qt.quit()}
}
Re: QML GridView: problems handling clicks [Partially solved]
one more answer in same thread: [url]http://www.developer.nokia.com/Community/Discussion/showthread.php?226883-QML-GridView-problems-handling-clicks[/url]
Re: QML GridView: problems handling clicks [Partially solved]
[QUOTE=njzk2;852807]I think your action should be between {} and not "". so:
ListElement {
...
action: {Qt.quit()}
}[/QUOTE]
Thanks! but that doesn''t work because ListElement not support such literals.
[QUOTE=Den123;853751]one more answer in same thread: [url]http://www.developer.nokia.com/Community/Discussion/showthread.php?226883-QML-GridView-problems-handling-clicks[/url][/QUOTE]
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.