MouseEvent jumps in custom window
-
Hi Guys,
I have a rather strange problem: I created a custom window like this:
Window { id: root flags: Qt.FramelessWindowHint default property list<Item> items property Component style: DockSettings.fromRessource("Styles/MyWindowStyle", root) readonly property Loader __styleComponent: Loader { id: styleComponentLoader sourceComponent: style property QtObject styleData: QtObject { readonly property alias windowX: root.x readonly property alias windowY: root.y readonly property var setPosition: root.setPosition } } readonly property Item header: Loader { id: headerLoader sourceComponent: __styleComponent.item.header parent: renderTarget } signal creationCompleted() function setPosition(x, y) { root.x = x root.y = y show() } Rectangle { id: renderTarget anchors.fill: parent } }And then I created a Style that is attached to it:
DockStyle { property Component header: Item { width: styleData.contentWidth height: 25 Rectangle { height: parent.height width: parent.width color: "lavender" MouseArea { anchors.fill: parent property bool dragging: false property point startPosition: Qt.point(0, 0) function startDragging(x, y) { dragging = true startPosition = Qt.point(x, y) } function stopDragging() { dragging = true startPosition = Qt.point(0, 0) } onPressed: { if(mouse.button === Qt.LeftButton) { startDragging(mouse.x, mouse.y) } } onReleased: { stopDragging() } onPositionChanged: { if(dragging) { styleData.setPosition(styleData.windowX + mouse.x - startPosition.x, styleData.windowY + mouse.y - startPosition.y) console.log(mouse.x, styleData.windowX) } } } } } }As you can see I created my own header for the window and want to make it moveable over the screen. Which in general works but I always get some random mouse positions in between. Log output looks like this (just dragging it slowly left to right):
qml: 92 2352 qml: -5 2281 qml: -21 2194 qml: -22 2106 qml: -22 2018 qml: 309 2437 qml: 307 2678 qml: -355 2257 qml: -356 1835 qml: 487 2256 qml: 66 2256Where are those random values come from and how do I get rid of them?
Thanks a lot
Nils -
Hi Guys,
I have a rather strange problem: I created a custom window like this:
Window { id: root flags: Qt.FramelessWindowHint default property list<Item> items property Component style: DockSettings.fromRessource("Styles/MyWindowStyle", root) readonly property Loader __styleComponent: Loader { id: styleComponentLoader sourceComponent: style property QtObject styleData: QtObject { readonly property alias windowX: root.x readonly property alias windowY: root.y readonly property var setPosition: root.setPosition } } readonly property Item header: Loader { id: headerLoader sourceComponent: __styleComponent.item.header parent: renderTarget } signal creationCompleted() function setPosition(x, y) { root.x = x root.y = y show() } Rectangle { id: renderTarget anchors.fill: parent } }And then I created a Style that is attached to it:
DockStyle { property Component header: Item { width: styleData.contentWidth height: 25 Rectangle { height: parent.height width: parent.width color: "lavender" MouseArea { anchors.fill: parent property bool dragging: false property point startPosition: Qt.point(0, 0) function startDragging(x, y) { dragging = true startPosition = Qt.point(x, y) } function stopDragging() { dragging = true startPosition = Qt.point(0, 0) } onPressed: { if(mouse.button === Qt.LeftButton) { startDragging(mouse.x, mouse.y) } } onReleased: { stopDragging() } onPositionChanged: { if(dragging) { styleData.setPosition(styleData.windowX + mouse.x - startPosition.x, styleData.windowY + mouse.y - startPosition.y) console.log(mouse.x, styleData.windowX) } } } } } }As you can see I created my own header for the window and want to make it moveable over the screen. Which in general works but I always get some random mouse positions in between. Log output looks like this (just dragging it slowly left to right):
qml: 92 2352 qml: -5 2281 qml: -21 2194 qml: -22 2106 qml: -22 2018 qml: 309 2437 qml: 307 2678 qml: -355 2257 qml: -356 1835 qml: 487 2256 qml: 66 2256Where are those random values come from and how do I get rid of them?
Thanks a lot
Nils- in your stopDragging() you should set
dragging = false - in the onPressed / onReleased / onPositionChanged add a
mouse.accepted = trueto prevent event propagation
- in your stopDragging() you should set
-
Good spots but neither of those two things fixed it.
But I think I found the answer. I realized that this just happens in one of my setups where I use Windows Subsystem for Linux and xming. It does not happen on my Mac OS X or my Linux system. I then recactivated my old mingw setup on the Window system and it also not happen. So my best guess is that it is a bug in xming or the integration layer.
I tested with exactly the same qt versions on all systems so yeah it is not a Qt thing so I mark this as solved.