diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-09-01 22:27:24 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-09-01 22:27:33 +0800 |
| commit | d5f54be8d71734c9c59f5275c47b02fdec8c3cdf (patch) | |
| tree | d5e22aa0d4fb193f86f9cfed52a3ef3f5fe110ad /components | |
| parent | 8cc633f4a6c04898f335b82cb423526c48cab574 (diff) | |
fix(App): mouse selected unintentionally
Diffstat (limited to 'components')
| -rw-r--r-- | components/IMouseArea.qml | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/components/IMouseArea.qml b/components/IMouseArea.qml new file mode 100644 index 0000000..4c360ed --- /dev/null +++ b/components/IMouseArea.qml @@ -0,0 +1,45 @@ +/// NOTE: This is not zero cost, there's performance penalty, only use this instead of mousearea if hover is strictly required to be still +/// Such as when the component may appear where the mouse is already is + +import QtQuick + +MouseArea { + hoverEnabled: true + + property real gx: Number.MAX_VALUE + property real gy: Number.MAX_VALUE + + property bool hovered: false + + signal entered_ + signal positionChanged_(var mouse) + + onPositionChanged: mouse => { + let gpos = mapToItem(null, mouse.x, mouse.y); + + if (gx === Number.MAX_VALUE && gy === Number.MAX_VALUE) { + gx = gpos.x; + gy = gpos.y; + return; + } + + if (gpos.x === gx && gpos.y === gy) + return; + + gx = gpos.x; + gy = gpos.y; + + if (!hovered) { + hovered = true; + entered_(); + } + + positionChanged_(mouse); + } + + onExited: { + hovered = false; + gx = Number.MAX_VALUE; + gy = Number.MAX_VALUE; + } +} |
