<?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[Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work.]]></title><description><![CDATA[<p dir="auto">Hi there,</p>
<p dir="auto">in a bigger project I try too create a dialog for editing whitepoint and greybalance.<br />
In order to trace and detect my issue I have extracted the minimal code.</p>
<p dir="auto">What do I have: A dialog with 2 GroupBoxes. Each has a GraphicsView and his own scene.<br />
After painting a background I add an ellipse-item and set:</p>
<pre><code>QGraphicsEllipseItem *ellipse = new QGraphicsEllipseItem (250 -5, 250 - 5, 10, 10);    
ellipse-&gt;setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemSendsScenePositionChanges | QGraphicsItem::ItemSendsGeometryChanges);
scene-&gt;addItem(ellipse);
</code></pre>
<p dir="auto">I do this, because I aim to grab and move this circle - which works.<br />
Now I try to react on the movement and position changes. In my minimal.h .</p>
<pre><code>void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
</code></pre>
<p dir="auto">In my minimal.cpp</p>
<pre><code>void WpEditor::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    mPoint = event-&gt;pos();
    qDebug() &lt;&lt; "Mouse move " &lt;&lt; mPoint;
    QGraphicsScene::mouseMoveEvent(event);
}
</code></pre>
<p dir="auto">My issue: Nothing happens. What I am doing wrong here.</p>
<p dir="auto">thx and regards</p>
<p dir="auto"><strong>PS: If you need the full example pls let me know where to send it. I still can't upload here.</strong></p>
]]></description><link>https://forum.qt.io/topic/139457/cant-get-mousemoveevent-qgraphicsscenemouseevent-mouseevent-to-work</link><generator>RSS for Node</generator><lastBuildDate>Mon, 26 Oct 2026 00:52:14 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139457.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Sep 2022 18:12:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work. on Wed, 21 Sep 2022 12:51:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mchinand">@<bdi>mchinand</bdi></a></p>
<p dir="auto">hi you are right - I want to change parameters according to x/y changes.<br />
I will have a look at you solution too! And come back of course.</p>
]]></description><link>https://forum.qt.io/post/729638</link><guid isPermaLink="true">https://forum.qt.io/post/729638</guid><dc:creator><![CDATA[ademmler]]></dc:creator><pubDate>Wed, 21 Sep 2022 12:51:35 GMT</pubDate></item><item><title><![CDATA[Reply to Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work. on Wed, 21 Sep 2022 12:48:04 GMT]]></title><description><![CDATA[<p dir="auto">What are you actually trying to do? I had <a href="https://forum.qt.io/topic/139457/cant-get-mousemoveevent-qgraphicsscenemouseevent-mouseevent-to-work/4">suggested</a> using a QGraphicsObject and its signals because I thought you were moving around the ellipse you create to change two parameters that affect other things in your application/UI and its position would reflect the current value of those parameters. If this is the case, even if you do this by watching mouse events in the scene, you will want to use changes in the ellipse object's position to make your parameter changes.</p>
]]></description><link>https://forum.qt.io/post/729637</link><guid isPermaLink="true">https://forum.qt.io/post/729637</guid><dc:creator><![CDATA[mchinand]]></dc:creator><pubDate>Wed, 21 Sep 2022 12:48:04 GMT</pubDate></item><item><title><![CDATA[Reply to Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work. on Wed, 21 Sep 2022 12:09:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ademmler">@<bdi>ademmler</bdi></a><br />
Yes, you can always do sub-classing/events via <code>eventFilter()</code> if that is what you want.  It can avoid need for sub-classing in some cases, but the code is/may be "messier" then overriding the methods you need.  As you please.</p>
]]></description><link>https://forum.qt.io/post/729629</link><guid isPermaLink="true">https://forum.qt.io/post/729629</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 21 Sep 2022 12:09:04 GMT</pubDate></item><item><title><![CDATA[Reply to Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work. on Wed, 21 Sep 2022 12:03:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a>  thx again JonB.</p>
<p dir="auto">Either I subclass QGraphicsScene - as you wrote before or using an event filter might help. I found this thread about it.<br />
<a href="https://stackoverflow.com/questions/51151806/use-a-qgraphicsscenemouseevent-in-a-class-that-inherits-from-qgraphicsview" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/51151806/use-a-qgraphicsscenemouseevent-in-a-class-that-inherits-from-qgraphicsview</a></p>
<pre><code>bool DisplayImage::eventFilter(QObject *watched, QEvent *event)
{
    if(watched == scene){
        // press event
        QGraphicsSceneMouseEvent *mouseSceneEvent;
        if(event-&gt;type() == QEvent::GraphicsSceneMousePress){
            mouseSceneEvent = static_cast&lt;QGraphicsSceneMouseEvent *&gt;(event);
            qDebug()&lt;&lt;mouseSceneEvent-&gt;scenePos()&lt;&lt;mouseSceneEvent-&gt;lastScenePos();
           // your logic here
        }
        // move event
        else if (event-&gt;type() == QEvent::GraphicsSceneMouseMove) {
            mouseSceneEvent = static_cast&lt;QGraphicsSceneMouseEvent *&gt;(event);
            qDebug()&lt;&lt;mouseSceneEvent-&gt;scenePos()&lt;&lt;mouseSceneEvent-&gt;lastScenePos();
            // your logic here
        }
        // release event
        else if (event-&gt;type() == QEvent::GraphicsSceneMouseRelease) {
            mouseSceneEvent = static_cast&lt;QGraphicsSceneMouseEvent *&gt;(event);
            qDebug()&lt;&lt;mouseSceneEvent-&gt;scenePos()&lt;&lt;mouseSceneEvent-&gt;lastScenePos();
            // your logic here
        }
    }
    return QGraphicsView::eventFilter(watched, event);
}
</code></pre>
]]></description><link>https://forum.qt.io/post/729626</link><guid isPermaLink="true">https://forum.qt.io/post/729626</guid><dc:creator><![CDATA[ademmler]]></dc:creator><pubDate>Wed, 21 Sep 2022 12:03:01 GMT</pubDate></item><item><title><![CDATA[Reply to Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work. on Wed, 21 Sep 2022 10:05:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ademmler">@<bdi>ademmler</bdi></a> said in <a href="/post/729598">Cant get "mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)" to work.</a>:</p>
<blockquote>
<p dir="auto">error: non-virtual member function marked 'override' hides virtual member function<br />
Honestly I have never understood when I can override a QT function and when I can't.</p>
</blockquote>
<p dir="auto">This is totally a C++ issue, nothing special about Qt.  And it is <em>really</em> easy to tell:</p>
<ul>
<li>If a method is marked <code>virtual</code> you <em>can</em> <code>override</code> it.  And Qt docs will always show <code>virtual</code> for such methods.</li>
<li>If a method is <em>not</em> marked <code>virtual</code> you <em>cannot</em> <code>override</code> it.</li>
</ul>
<p dir="auto">"Simplez" :)  <code>override</code> is not mandatory, but I suggest you should <em>always</em> put it in if you are intending to override a method.  Because you get an error then if the method, or its signature, are <em>not</em> virtual/overridable, and you will know.  And in this case the error message tells you exactly that.</p>
<p dir="auto">So you must either <em>sub-class</em> your <code>QGraphicsScene</code> and override its <code>void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)</code> (which I have never tried) or you need to override the <code>QGraphicsView::mouseMoveEvent(QMouseEvent *event)</code> in your <code>WpEditor</code>.  In this case, confirm that you will <em>keep the left mouse pressed down</em> while you do drag-move, else you will need to call <code>QGraphicsView::setMouseTracking(true)</code> .</p>
<p dir="auto">Meanwhile, I noticed your original <code>QGraphicsScene::mouseMoveEvent(event);</code> in <code>WpEditor::mouseMoveEvent()</code>, your <em>attempt</em> to call the base class implementation.  I took you at your word, but you need <code>QGraphicsView::mouseMoveEvent(event);</code> instead!</p>
]]></description><link>https://forum.qt.io/post/729600</link><guid isPermaLink="true">https://forum.qt.io/post/729600</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 21 Sep 2022 10:05:33 GMT</pubDate></item><item><title><![CDATA[Reply to Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work. on Wed, 21 Sep 2022 09:54:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ademmler">@<bdi>ademmler</bdi></a> said in <a href="/post/729598">Cant get "mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)" to work.</a>:</p>
<blockquote>
<p dir="auto">error: non-virtual member function marked 'override' hides virtual member function</p>
</blockquote>
<p dir="auto">Show the code. You're not correctly overriding.</p>
]]></description><link>https://forum.qt.io/post/729599</link><guid isPermaLink="true">https://forum.qt.io/post/729599</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 21 Sep 2022 09:54:20 GMT</pubDate></item><item><title><![CDATA[Reply to Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work. on Wed, 21 Sep 2022 09:52:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/729511">Cant get "mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)" to work.</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ademmler">@<bdi>ademmler</bdi></a></p>
</blockquote>
<p dir="auto">Dear JonB - thx for your feedback.</p>
<blockquote>
<p dir="auto">You mean your method is not hit?  Start by appending <code>override</code> in the <code>.h</code> file to be sure.</p>
</blockquote>
<p dir="auto">When I do so I get:<br />
error: non-virtual member function marked 'override' hides virtual member function<br />
Honestly I have never understood when I can override a QT function and when I can't.</p>
<blockquote>
<p dir="auto">WpEditor<code>is indeed a</code>QGraphicsScene<code>and not a</code>QGraphicsView`, right?</p>
</blockquote>
<p dir="auto">It is a QGrahicsview (in an UI file) which I attache a scene to. In the constructor I do:<br />
... some stuff<br />
sceneWp = new QGraphicsScene(0, 0, 500, 500);<br />
viewWp-&gt;setScene(sceneWp);<br />
... some more stuff</p>
<blockquote>
<p dir="auto">In the event I think you will want to use <code>event-&gt;scenePos();</code> rather than <code>event-&gt;pos();</code>.</p>
</blockquote>
<p dir="auto">Yes this is correct - my fault !</p>
]]></description><link>https://forum.qt.io/post/729598</link><guid isPermaLink="true">https://forum.qt.io/post/729598</guid><dc:creator><![CDATA[ademmler]]></dc:creator><pubDate>Wed, 21 Sep 2022 09:52:14 GMT</pubDate></item><item><title><![CDATA[Reply to Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work. on Tue, 20 Sep 2022 18:44:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ademmler">@<bdi>ademmler</bdi></a> said in <a href="/post/729510">Cant get "mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)" to work.</a>:</p>
<blockquote>
<p dir="auto">void WpEditor::mouseMoveEvent(QGraphicsSceneMouseEvent *event)</p>
</blockquote>
<p dir="auto">What is your <code>WpEditor</code> class a sub-class of?</p>
]]></description><link>https://forum.qt.io/post/729513</link><guid isPermaLink="true">https://forum.qt.io/post/729513</guid><dc:creator><![CDATA[mchinand]]></dc:creator><pubDate>Tue, 20 Sep 2022 18:44:10 GMT</pubDate></item><item><title><![CDATA[Reply to Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work. on Tue, 20 Sep 2022 18:26:28 GMT]]></title><description><![CDATA[<p dir="auto">It might be easier to sub-class <a href="https://doc.qt.io/qt-6/qgraphicsobject.html#details" target="_blank" rel="noopener noreferrer nofollow ugc">QGraphicsObject</a> and then make connections to its x/yChanged() signals.</p>
]]></description><link>https://forum.qt.io/post/729512</link><guid isPermaLink="true">https://forum.qt.io/post/729512</guid><dc:creator><![CDATA[mchinand]]></dc:creator><pubDate>Tue, 20 Sep 2022 18:26:28 GMT</pubDate></item><item><title><![CDATA[Reply to Cant get &quot;mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)&quot; to work. on Tue, 20 Sep 2022 18:42:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ademmler">@<bdi>ademmler</bdi></a><br />
You mean your method is not hit?  Start by appending <code>override</code> in the <code>.h</code> file to be sure.</p>
<p dir="auto"><code>WpEditor</code> is indeed a <code>QGraphicsScene</code> and not a <code>QGraphicsView</code>, right?</p>
<p dir="auto">In the event I think you will want to use <code>event-&gt;scenePos();</code> rather than <code>event-&gt;pos();</code>.</p>
]]></description><link>https://forum.qt.io/post/729511</link><guid isPermaLink="true">https://forum.qt.io/post/729511</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 20 Sep 2022 18:42:40 GMT</pubDate></item></channel></rss>