<?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[Random MousePressOffset]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I recently run into a problem using <code>QMouseEvent</code>  - Press, Release and Move.</p>
<p dir="auto">In the end I was able to fix it, but I'm puzzled, why this was a problem in the first place. Maybe someone can enlighten me on what is going on.</p>
<p dir="auto">Ok, the MousePress Origin was saved like this:</p>
<pre><code>mousePressEvent(QMouseEvent *event){
   pointPressed = event-&gt;pos();
}
</code></pre>
<p dir="auto">In mouse move I had the following:</p>
<pre><code>mouseMoveEvent(QMouseEvent *event){
   int distY = pointPressed.y() - event-&gt;y();
   this-&gt;move(this-&gt;x(),0-distY);
}
</code></pre>
<p dir="auto">For fast mousemoves, everything works fine, for slow movement of the mouse however, the widgets gets 'stuttery'. It jumps back and forth.</p>
<p dir="auto">Turns out,  pointPressed actually chages its value by 1, even so mousebutton is not pressed again. Found with</p>
<pre><code>qDebug() &lt;&lt; pointPressed; //In mouseMoveEvent
</code></pre>
<p dir="auto">fixed it with the following:</p>
<pre><code>//MousePressEvent
pointPressed = mapToGlobal(event-&gt;pos());

//mouseMoveEvent
QPoint eveGl = mapToGlobal(event-&gt;pos());
int distY = pointPressed.y() - eveGl.y();
</code></pre>
<p dir="auto">By the way, <code>pointPressed = mapToGlobal(event-&gt;pos());</code> has to happen in <code>MousePressEvent</code> . If I do both maptoGlobals in the mouseMoveEvent I have the same behaviour as if I used local coordinates.</p>
<p dir="auto">If any one could explain that to me, I would be very grateful.</p>
]]></description><link>https://forum.qt.io/topic/76790/random-mousepressoffset</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 21:29:47 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/76790.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Mar 2017 12:51:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Random MousePressOffset on Fri, 03 Mar 2017 10:48:47 GMT]]></title><description><![CDATA[<p dir="auto">Turns out <a class="plugin-mentions-user plugin-mentions-a" href="/user/kragnfrol">@<bdi>kragnfrol</bdi></a> answered my question. Probably without knowladge of this topics existence x)</p>
<p dir="auto">from the definition of <a href="http://doc.qt.io/qt-5/qmouseevent.html#pos" target="_blank" rel="noopener noreferrer nofollow ugc">QPoint QMouseEvent::pos() const</a></p>
<p dir="auto">Those who are able to read are at an advantage indeed...</p>
]]></description><link>https://forum.qt.io/post/379615</link><guid isPermaLink="true">https://forum.qt.io/post/379615</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Fri, 03 Mar 2017 10:48:47 GMT</pubDate></item></channel></rss>