<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Reparenting QGraphicsItem during Mouse Drag</title>
	<atom:link href="http://blog.zx2c4.com/275/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.zx2c4.com/275</link>
	<description>{{{ ZX2C4 }}}</description>
	<lastBuildDate>Sat, 12 May 2012 12:43:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Anthony</title>
		<link>http://blog.zx2c4.com/275#comment-6718</link>
		<dc:creator>Anthony</dc:creator>
		<pubDate>Mon, 27 Feb 2012 01:10:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.zx2c4.com/?p=275#comment-6718</guid>
		<description>I see this post is old, but I&#039;m experiencing the same problem. As I move around some QGraphicsItems, I want them to &quot;snap&quot; to some other items, and it works visually, but when I try to click on them after moving, it doesn&#039;t work.

Did you ever figure out a nicer solution?</description>
		<content:encoded><![CDATA[<p>I see this post is old, but I&#8217;m experiencing the same problem. As I move around some QGraphicsItems, I want them to &#8220;snap&#8221; to some other items, and it works visually, but when I try to click on them after moving, it doesn&#8217;t work.</p>
<p>Did you ever figure out a nicer solution?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gopala Krishna A</title>
		<link>http://blog.zx2c4.com/275#comment-1735</link>
		<dc:creator>Gopala Krishna A</dc:creator>
		<pubDate>Wed, 23 Jun 2010 08:47:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.zx2c4.com/?p=275#comment-1735</guid>
		<description>Probably you can simulate a mouse press on reparenting. (and use timer with 0 timeout just to ensure you are doing things in a fresh event loop iteration)</description>
		<content:encoded><![CDATA[<p>Probably you can simulate a mouse press on reparenting. (and use timer with 0 timeout just to ensure you are doing things in a fresh event loop iteration)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Donenfeld</title>
		<link>http://blog.zx2c4.com/275#comment-1730</link>
		<dc:creator>Jason Donenfeld</dc:creator>
		<pubDate>Tue, 22 Jun 2010 21:19:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.zx2c4.com/?p=275#comment-1730</guid>
		<description>@giucam
This works for updating the position as far as reparenting goes, but the mouse event is still tied to the original position, so the item is moved to the correct place initially, but as soon as you move the mouse again after it&#039;s been reparented, it jumps all over.

@aseigo
Good thinking. But I don&#039;t think I really want to do this. The way my application is setup, I have some bounds checking to ensure that child rectangles are never moved outside their parent until they&#039;re reparented when the drag destination is fully enclosed in the new parent. This makes dragging rectangles from one place to another &quot;stick&quot; at the border between them until the user has deliberately dragged it far enough in.

Put more simply, doing something like that is incompatible with this:

QRectF transformed = transform().mapRect(boundingRect());
		if (newPoint.x() &lt; -transformed.x())
			newPoint.setX(-transformed.x());
		if (newPoint.y() &lt; transformed.y())
			newPoint.setY(-transformed.y());
		if (newPoint.x() &gt; parentItem()-&gt;boundingRect().width() - transformed.width() - transformed.x())
			newPoint.setX(parentItem()-&gt;boundingRect().width() - transformed.width() - transformed.x());
		if (newPoint.y() &gt; parentItem()-&gt;boundingRect().height() - transformed.height() - transformed.y())
			newPoint.setY(parentItem()-&gt;boundingRect().height() - transformed.height() - transformed.y());
		return newPoint;</description>
		<content:encoded><![CDATA[<p>@giucam<br />
This works for updating the position as far as reparenting goes, but the mouse event is still tied to the original position, so the item is moved to the correct place initially, but as soon as you move the mouse again after it&#8217;s been reparented, it jumps all over.</p>
<p>@aseigo<br />
Good thinking. But I don&#8217;t think I really want to do this. The way my application is setup, I have some bounds checking to ensure that child rectangles are never moved outside their parent until they&#8217;re reparented when the drag destination is fully enclosed in the new parent. This makes dragging rectangles from one place to another &#8220;stick&#8221; at the border between them until the user has deliberately dragged it far enough in.</p>
<p>Put more simply, doing something like that is incompatible with this:</p>
<p>QRectF transformed = transform().mapRect(boundingRect());<br />
		if (newPoint.x() < -transformed.x())<br />
			newPoint.setX(-transformed.x());<br />
		if (newPoint.y() < transformed.y())<br />
			newPoint.setY(-transformed.y());<br />
		if (newPoint.x() > parentItem()->boundingRect().width() &#8211; transformed.width() &#8211; transformed.x())<br />
			newPoint.setX(parentItem()->boundingRect().width() &#8211; transformed.width() &#8211; transformed.x());<br />
		if (newPoint.y() > parentItem()->boundingRect().height() &#8211; transformed.height() &#8211; transformed.y())<br />
			newPoint.setY(parentItem()->boundingRect().height() &#8211; transformed.height() &#8211; transformed.y());<br />
		return newPoint;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Seigo</title>
		<link>http://blog.zx2c4.com/275#comment-1729</link>
		<dc:creator>Aaron Seigo</dc:creator>
		<pubDate>Tue, 22 Jun 2010 21:03:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.zx2c4.com/?p=275#comment-1729</guid>
		<description>the first thing i wondered is why you aren&#039;t reparenting on mouse release? you can certainly check what plate is under the food item while it is moving, and even have the plate respond visually in some way (or even &quot;reject&quot; the item, e.g. if it was &quot;full&quot;) .. but maybe just reparent when the movement actually stops?</description>
		<content:encoded><![CDATA[<p>the first thing i wondered is why you aren&#8217;t reparenting on mouse release? you can certainly check what plate is under the food item while it is moving, and even have the plate respond visually in some way (or even &#8220;reject&#8221; the item, e.g. if it was &#8220;full&#8221;) .. but maybe just reparent when the movement actually stops?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: giucam</title>
		<link>http://blog.zx2c4.com/275#comment-1728</link>
		<dc:creator>giucam</dc:creator>
		<pubDate>Tue, 22 Jun 2010 21:00:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.zx2c4.com/?p=275#comment-1728</guid>
		<description>I&#039;m doing lot of reparenting when moving QGraphicsItems in my project (playgrund/base/plasma/containments/groupingdesktop) and all i need to do is:

QPointF pos = item-&gt;scenePos();
item-&gt;setParentItem(newParent);
item-&gt;setPos(newParent-&gt;mapFromScene(pos));</description>
		<content:encoded><![CDATA[<p>I&#8217;m doing lot of reparenting when moving QGraphicsItems in my project (playgrund/base/plasma/containments/groupingdesktop) and all i need to do is:</p>
<p>QPointF pos = item-&gt;scenePos();<br />
item-&gt;setParentItem(newParent);<br />
item-&gt;setPos(newParent-&gt;mapFromScene(pos));</p>
]]></content:encoded>
	</item>
</channel>
</rss>

