Details
-
Suggestion
-
Resolution: Done
-
P3: Somewhat important
-
None
-
6f84a09dfbd15aac023580cf06e7b8c24f3b524c
Description
It is documented that a MouseArea's containsMouse property is only updated when the mouse actually moves:
Warning: This property is not updated if the area moves under the mouse: containsMouse will not change. In addition, if hoverEnabled is false, containsMouse will only be valid when the mouse is pressed while the mouse cursor is inside the MouseArea.
This presents problems for scenarios like the one below:
import QtQuick 2.4 import QtQuick.Controls 1.3 Rectangle { id: mainMenu activeFocusOnTab: false width: 650 height: 600 ListView { id: listView anchors.centerIn: parent width: 200 height: 300 model: ListModel { Component.onCompleted: { for (var i = 0; i < 10; ++i) { append({name: i + 1}); } } } delegate: Rectangle { width: listView.width height: 30 color: "black" Text { text: modelData color: mouseArea.containsMouse ? "white" : "grey" anchors.centerIn: parent } MouseArea { id: mouseArea anchors.fill: parent hoverEnabled: true onClicked: listView.model.remove(index) } } } }
The user would expect that by removing an item from the list, the item that takes the removed item's place (if any) would be highlighted, but it's not.
There might not be a declarative way to solve this problem, but we could provide a function that simply checks the last mouse position and updates containsMouse on demand:
// ... ListView { // ... delegate: Rectangle { // ... MouseArea { id: mouseArea anchors.fill: parent hoverEnabled: true onClicked: listView.model.remove(index) Connections { target: listView onCountChanged: mouseArea.refresh() // or: onCountChanged: mouseArea.refreshContainsMouse() // or: onCountChanged: mouseArea.checkIfContainsMouse() } } } } }
Attachments
Issue Links
- is duplicated by
-
QTBUG-52537 MouseArea.onEntered not fired if component arrives under mouse
-
- Closed
-
- relates to
-
QTBUG-88119 MouseArea::containsMouse incorrectly set to true upon toggle visible true
-
- Reported
-
-
QTBUG-37482 containsMouse property not updated when switching tabs in TabView programmatically
-
- Closed
-
-
QTBUG-40475 MouseArea doesn't receive hover event if cursor isn't moving
-
- Closed
-
-
QTBUG-36930 containsMouse property not updated correctly for overlapping mouse areas during dragging
-
- Open
-
For Gerrit Dashboard: QTBUG-42194 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
127724,5 | QQuickWindow: Process a synthetic hover once per frame | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |