<?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[[Solved] QGraphicsIte setPos , moveBy - how do they work?]]></title><description><![CDATA[<p dir="auto">I looked at the "colliding mouse example":<a href="http://doc.qt.nokia.com/4.7-snapshot/graphicsview-collidingmice.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.nokia.com/4.7-snapshot/graphicsview-collidingmice.html</a> that ships with Qt.<br />
It took me several days to figure out<br />
@setPos(mapToParent(0,1));@</p>
<p dir="auto">moves a QGraphicsItem downwards, everytime 'advance' (QGraphicsView function) is called. I don't understand how this works.</p>
<p dir="auto">(This is not part of the code, but I modified the 'setPos' function slightly to see how it works)</p>
<p dir="auto">I had to rummage though the code to figure out what was moving the QGraphicsItem. I expected to see something like</p>
<p dir="auto">@setPos(mapToParent(0,ypos));@</p>
<p dir="auto">to move something downwards, with ypos incremented in 'advance' member function in QGraphicsItem. This seems more intuitive to me. However, it seems this causes the item to move with a constant acceleration.</p>
<p dir="auto">I also saw another function somewhere else that works exactly the same way (Correct me if I am wrong)<br />
@moveBy(0,1);@</p>
<p dir="auto">Now this seems intuitive to me. Everytime advance is called, the item is 'moved <em>by</em>' (0,1)</p>
<p dir="auto">Could somebody explain how setPos works?<br />
Thanks!</p>
]]></description><link>https://forum.qt.io/topic/15401/solved-qgraphicsite-setpos-moveby-how-do-they-work</link><generator>RSS for Node</generator><lastBuildDate>Fri, 23 Oct 2026 16:09:51 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/15401.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 28 Mar 2012 03:42:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Solved] QGraphicsIte setPos , moveBy - how do they work? on Wed, 28 Mar 2012 13:20:37 GMT]]></title><description><![CDATA[<p dir="auto">Thanks sraboisson! Wonderful explanation. Ah so 'increment' part comes from mapToParent as you showed in the code. I think the reason it did not occur to me was I didn't think the origin changed everytime setpos(mapToParent(..)) was called.</p>
]]></description><link>https://forum.qt.io/post/133907</link><guid isPermaLink="true">https://forum.qt.io/post/133907</guid><dc:creator><![CDATA[Mathai]]></dc:creator><pubDate>Wed, 28 Mar 2012 13:20:37 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] QGraphicsIte setPos , moveBy - how do they work? on Wed, 28 Mar 2012 08:53:06 GMT]]></title><description><![CDATA[<p dir="auto">The confusion does not come from your interpretation of "setPos" (which acts as you expect), but from the "mapToParent" function</p>
<p dir="auto">THIS is the important point:<br />
The "mapToParent" function converts a coordinate in item coordinates to coordinate in parent's coordinate system (or scene coordinates if no parent)</p>
<p dir="auto">For example, if you have a mouse "myMouse" at (10,10) in your scene:</p>
<ul>
<li>The "myMouse" local coordinates are (0,0), i.e origin of the mouse item</li>
<li>The "myMouse" coordinate in scene coordinates are (10,10).</li>
</ul>
<p dir="auto">A call myMouse.mapToParent(0,0) will return (10,10);<br />
A call myMouse.mapToParent(0,1) will return (10,11);</p>
<p dir="auto">and this is the point:<br />
@myMouse.setPos(10,10);             /*  Position the mouse in it's parent coordinate system : (10, 10)  <em>/<br />
newPos = myMouse.mapToParent(0,1); /</em>  newPos = (10,10) + (0,1) = (10, 11);  <em>/<br />
myMouse.setPos(newPos);            /</em>  Position the mouse in it's parent coordinate system : (10, 11)  <em>/<br />
newPos = myMouse.mapToParent(0,1); /</em>  newPos = (10,11) + (0,1) = (10, 12);  <em>/<br />
myMouse.setPos(newPos);            /</em>  Position the mouse in it's parent coordinate system : (10, 12)  */@</p>
<p dir="auto">and so on...</p>
<p dir="auto">Note: In the "colliding mice" sample, a mouse coordiantes system is yaxis = nose to tail axis: combining with the mouse item rotation, a mouse does not only go down, but in the good direction</p>
<p dir="auto">Perhaps, "The Graphics View Coordinate System":<a href="http://qt-project.org/doc/qt-4.8/graphicsview.html#the-graphics-view-coordinate-system" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-4.8/graphicsview.html#the-graphics-view-coordinate-system</a> can help...</p>
]]></description><link>https://forum.qt.io/post/133876</link><guid isPermaLink="true">https://forum.qt.io/post/133876</guid><dc:creator><![CDATA[sraboisson]]></dc:creator><pubDate>Wed, 28 Mar 2012 08:53:06 GMT</pubDate></item></channel></rss>