Highlight problem for ListView entry when button pressed
-
wrote on 26 Oct 2011, 11:32 last edited by
Hello.
I'm new in QLM and I have a problem with some task related to QML ListView. I need to make entries highlighted when pointed by mouse and selected when clicked. Everything works ok untill I press a button on some entry an than move to another - hover doesn't work for other entries. It looks that pressed button blocks other elements (no onEntered, onExited and other signals of those elements). Here is a similar, simplified code (and without selection action for now):ListDelegate.qml
@
import QtQuick 1.0Rectangle {
id: delegate
width: ListView.view.width
height: 40Rectangle { id: background anchors.fill: parent color: mArea.containsMouse ? "thistle" : "lightsteelblue" } Text { id: label anchors.top: parent.top anchors.topMargin: 2 anchors.left: parent.left anchors.leftMargin: 2 font.family: "Helvetica"; font.pixelSize: 13; font.bold: true color: mArea.containsMouse ? "blue" : "red" text: name + ":\n\t" + number + "\n" } MouseArea { id: mArea anchors.fill: parent hoverEnabled: true }
}
@ContactModel.qml
@
import QtQuick 1.0ListModel {
ListElement {
name: "Bill Smith"
number: "555 3264"
}
ListElement {
name: "John Brown"
number: "555 8426"
}
ListElement {
name: "Sam Wise"
number: "555 0473"
}
}
@main.qml
@
import QtQuick 1.0Rectangle {
width: 180; height: 200ListView { id: list width: 180; height: 200 clip: true interactive: false model: ContactModel {} delegate: ListDelegate {} focus: true }
}
@Is there any solution (the simpler - the better :) )?
-
wrote on 26 Oct 2011, 23:18 last edited by
Hi,
Are you pressing the mouse button and then moving into another entry with the mouse button still pressed? In Qt (and QML), accepting a mouse press will "grab" all further mouse events until the button is released. In this case that means that the MouseArea you pressed in will get all mouse events (and the MouseAreas in other entries will get none), until the button is released.
Regards,
Michael -
wrote on 27 Oct 2011, 12:34 last edited by
Yes, it is exactly what I am doing. Is there any solution to stop sending all events only to that single MouseArea?
Thanks
-
wrote on 28 Oct 2011, 00:46 last edited by
I don't know of one unfortunately -- hopefully others can chime in with some possible solutions.
Regards,
Michael -
wrote on 28 Oct 2011, 08:32 last edited by
AFAIK, there is no way to do that directly. The only way I can think of, is to not use a mouse area per item, but a mouse area that overlays the whole list instead. You can then use indexAt to get the indexes from your starting to your end point, so you should be able to calculate which items should be selected from that. The actual selection then needs to be set as a property of the items, I would say, so the delegates can highlight them.
Note that I did not try to do this myself.
-
wrote on 3 Jul 2013, 21:19 last edited by
I am having the same kind of problem, did you or anyone else find a solution to this problem in the meanwhile?
Thanks in advance