Contact List example: make ContactDelegate.ui.qml designable

Replace the MouseArea and its onClicked signal handler with a checkable
AbstractButton to achieve declarative bindings and that way make it
possible to open ContactDelegate.ui.qml in Qt Quick Designer.

Change-Id: I764e0adc23d4a0d44dd6660ed14e224a4e0e30c7
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
J-P Nurmi 2016-11-17 09:14:08 +01:00
parent 6a86efd939
commit fe34af03e3
1 changed files with 5 additions and 19 deletions

View File

@ -51,8 +51,10 @@
import QtQuick 2.7
import QtQuick.Controls 2.1
Item {
AbstractButton {
clip: true
checkable: true
autoExclusive: true
id: delegate
@ -61,22 +63,6 @@ Item {
property alias edit: edit
width: 300
MouseArea {
id: mouseArea
anchors.fill: parent
}
Connections {
target: mouseArea
onClicked: {
if (delegate.ListView.view.currentIndex === index)
delegate.ListView.view.currentIndex = -1
else
delegate.ListView.view.currentIndex = index
}
}
Column {
id: column1
height: 400
@ -174,11 +160,11 @@ Item {
states: [
State {
name: "collapsed"
when: !delegate.ListView.isCurrentItem
when: !delegate.checked
},
State {
name: "expanded"
when: delegate.ListView.isCurrentItem
when: delegate.checked
PropertyChanges {
target: delegate