Skip to content

Instantly share code, notes, and snippets.

@Kakadu
Created February 8, 2014 18:57
Show Gist options
  • Save Kakadu/8888361 to your computer and use it in GitHub Desktop.
Save Kakadu/8888361 to your computer and use it in GitHub Desktop.
ListView for buttons with custom onclick events. In this implementation button onclick handler is placed in model near to useful properties of button. I don't want to place them far away of button descriptions because it breaks readability.
import QtQuick 2.0
Rectangle {
id: root
anchors { left: parent.left; right: parent.right }
height: 30
color: "gray"
radius: 15
border.width: 1
property alias title: textItem.text
property alias itemColor: root.color
signal listItemClick()
Text {
id: textItem
text: ""
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: listItemClick();
}
}
import QtQuick 2.0
Rectangle{
width:500
height:500
ListView {
width: parent.width
height: parent.height
clip: true
model: mainModel
spacing: 3
}
VisualItemModel {
id: mainModel
ListItem {
title: "asd"
color: "lightgray"
onListItemClick: console.log("Evaluate Fast Fourier transformation")
}
ListItem {
title: "qwer"
color: "green"
onListItemClick: console.log("Launch Nuclear Weapon")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment