MouseArea events on a Listview Component
-
Hello Community
We have the following code below and are using a touchscreen for operation:
import QtQuick 2.1 import QtQuick.Window 2.0 Window { visible: true id: box width: 360 height: 360 ListView { id: list anchors.top: parent.top anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: parent.right spacing: 0 model: 30 delegate: data clip: true focus: true smooth: true } Component{ id: data Item{ id: item width: list.width height: 30 clip: true; smooth: true; visible: true property string cellColor: getCellColor(index) Rectangle{ id: condData_item_line width: parent.width height: parent.height color: cellColor clip: true; smooth: true Text{ text: index anchors.centerIn: parent } MouseArea{ anchors.fill: parent onClicked: { console.log("click", index, mouse.x, mouse.y) } onPressed : { console.log("press", index, mouse.x, mouse.y) } onReleased: { console.log("release", index, mouse.x, mouse.y) } onCanceled: { console.log("cancel") } } } } } function getCellColor(index){ var color; if(index % 2 == 0){ color = "white"; }else{ color = "blue"; } return color; } }The question is the OnClicked and OnReleased events don't come up. Is this normal?
How should it be coded so we can get the OnReleased event of the Rectangle components.Best Regards
Yuri -
Hello Community
We have the following code below and are using a touchscreen for operation:
import QtQuick 2.1 import QtQuick.Window 2.0 Window { visible: true id: box width: 360 height: 360 ListView { id: list anchors.top: parent.top anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: parent.right spacing: 0 model: 30 delegate: data clip: true focus: true smooth: true } Component{ id: data Item{ id: item width: list.width height: 30 clip: true; smooth: true; visible: true property string cellColor: getCellColor(index) Rectangle{ id: condData_item_line width: parent.width height: parent.height color: cellColor clip: true; smooth: true Text{ text: index anchors.centerIn: parent } MouseArea{ anchors.fill: parent onClicked: { console.log("click", index, mouse.x, mouse.y) } onPressed : { console.log("press", index, mouse.x, mouse.y) } onReleased: { console.log("release", index, mouse.x, mouse.y) } onCanceled: { console.log("cancel") } } } } } function getCellColor(index){ var color; if(index % 2 == 0){ color = "white"; }else{ color = "blue"; } return color; } }The question is the OnClicked and OnReleased events don't come up. Is this normal?
How should it be coded so we can get the OnReleased event of the Rectangle components.Best Regards
Yuri -
@Yuri I would say to try adding "preventStealing: true" to your Mouse Area. I would also double check that the listveiw has a height and width > 0.
-
@Buttink Putting in "preventStealing: true" somehow prevented any operation on the listview. We double checked the dimension of the listview and seem fine.
-
@Yuri Hmm then I guess it must be related to touchscreen drivers or Qt configuration. May be you should ask on FreeScale community forum.
-
@p3c0 We thought that maybe just one of the problems. We just wanted to know if there was something wrong with the way the qml file was written.
-
@Yuri Who is the parent of
ListView? I just test the code withItemandWindowas parents on Android phone and it works as expected. -
@p3c0 I have updated the OP to include everything on the file. The parent is a Window. Also we just found out that if you touch the first item(index:0), it seem to fire up click and release properly.
-
@p3c0 I have updated the OP to include everything on the file. The parent is a Window. Also we just found out that if you touch the first item(index:0), it seem to fire up click and release properly.