<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MouseEvent jumps in custom window]]></title><description><![CDATA[<p dir="auto">Hi Guys,</p>
<p dir="auto">I have a rather strange problem: I created a custom window like this:</p>
<pre><code>Window {
    id: root

    flags: Qt.FramelessWindowHint

    default property list&lt;Item&gt; 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
    }
}
</code></pre>
<p dir="auto">And then I created a Style that is attached to it:</p>
<pre><code>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)
                    }
                }
            }
        }
    }
}
</code></pre>
<p dir="auto">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):</p>
<pre><code>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 2256
</code></pre>
<p dir="auto">Where are those random values come from and how do I get rid of them?</p>
<p dir="auto">Thanks a lot<br />
Nils</p>
]]></description><link>https://forum.qt.io/topic/95758/mouseevent-jumps-in-custom-window</link><generator>RSS for Node</generator><lastBuildDate>Wed, 06 May 2026 06:05:35 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/95758.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 21 Oct 2018 06:45:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MouseEvent jumps in custom window on Tue, 23 Oct 2018 16:04:05 GMT]]></title><description><![CDATA[<p dir="auto">Good spots but neither of those two things fixed it.<br />
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.<br />
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.</p>
]]></description><link>https://forum.qt.io/post/488512</link><guid isPermaLink="true">https://forum.qt.io/post/488512</guid><dc:creator><![CDATA[Nilres]]></dc:creator><pubDate>Tue, 23 Oct 2018 16:04:05 GMT</pubDate></item><item><title><![CDATA[Reply to MouseEvent jumps in custom window on Mon, 22 Oct 2018 06:52:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nilres">@<bdi>Nilres</bdi></a></p>
<ol>
<li>in your stopDragging() you should set <code>dragging = false</code></li>
<li>in the onPressed / onReleased / onPositionChanged add a <code>mouse.accepted = true</code> to prevent event propagation</li>
</ol>
]]></description><link>https://forum.qt.io/post/488170</link><guid isPermaLink="true">https://forum.qt.io/post/488170</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Mon, 22 Oct 2018 06:52:09 GMT</pubDate></item></channel></rss>