Highlight problem for ListView entry when button pressed
-
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 :) )?
-
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 -
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.