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 -
@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 Does it work properly on non touchscreen devices ?
-
@p3c0 Tried it with a mouse and seems to work fine.
-
@Yuri Which OS/Qt version combo are you using ?
-
@p3c0 Qt5 and Linux3.10.17
-
@Yuri Which Qt5 version and any specific Linux distro ?
-
@p3c0 Qt5.3.2 adn Linux is the BSP from Freescale. (The device is a freescale imx53 board)
-
@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 withItem
andWindow
as 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.
-
@Yuri That too works on Android. May be you should try with latest version viz.
Qt 5.4.1
-
@Yuri Also just to make sure can you try with
anchors.fill: parent
instead of those 4 anchors ?