<?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[Is it possible to do a drag and drop on an image to a rectangle?]]></title><description><![CDATA[<p dir="auto">I try to do a drag and drop on an image to a rectangle.</p>
<p dir="auto">I have an image whose id: icon<br />
@<br />
Image {<br />
id: icon<br />
width: 64<br />
height: 64<br />
source: "liverbird.gif"</p>
<pre><code>       MouseArea {
           id: liverbirdMouseArea
           anchors.fill: parent
           width: 64
           height: 64

           drag.target: parent
           drag.axis: Drag.XandYAxis
           onReleased: {
               cc.putItemIntoSlide(cubeFront, icon);
           }

       }
   }
</code></pre>
<p dir="auto">@</p>
<p dir="auto">and I try to put icon into a rectangle with id:cubeFront. So when I click icon, drag it to cubeFront, and release, I will go into the function putItemIntoSlide, which sets icon as a child of cubeFront.</p>
<p dir="auto">I check if icon is in cubeFront, by mapping the coordinates of icon to cubeFront, and then check if cubeFront contain this coordinates.</p>
<p dir="auto">@<br />
void cc::putItemIntoSlide(QGraphicsObject * slide, QGraphicsObject * object)<br />
{<br />
if (object != NULL)<br />
{<br />
if (slide-&gt;contains((slide-&gt;mapFromItem(object,object-&gt;pos()).toPoint())))<br />
{<br />
qDebug("got object in slide");<br />
object-&gt;setParentItem(slide);<br />
}<br />
}<br />
else<br />
{<br />
qDebug("no object");<br />
}<br />
}</p>
<p dir="auto">@</p>
<p dir="auto">But this doesn't work. Any suggestions? Much appreciated. =)</p>
]]></description><link>https://forum.qt.io/topic/6157/is-it-possible-to-do-a-drag-and-drop-on-an-image-to-a-rectangle</link><generator>RSS for Node</generator><lastBuildDate>Thu, 07 May 2026 01:22:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/6157.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 May 2011 11:20:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is it possible to do a drag and drop on an image to a rectangle? on Thu, 26 May 2011 11:51:48 GMT]]></title><description><![CDATA[<p dir="auto">I found the solution! This is an easy way to drag and drop in qt</p>
<p dir="auto">@<br />
QGraphicsItem *oldParent = object-&gt;parentItem();<br />
if (slide-&gt;contains((slide-&gt;mapFromItem(oldParent,object-&gt;pos()))))<br />
{<br />
qDebug("got object in slide");<br />
object-&gt;setParentItem(slide);<br />
object-&gt;setPos(slide-&gt;mapFromItem(oldParent,object-&gt;pos()));<br />
}<br />
else<br />
{<br />
object-&gt;setParentItem(0);<br />
}</p>
<p dir="auto">@</p>
]]></description><link>https://forum.qt.io/post/89680</link><guid isPermaLink="true">https://forum.qt.io/post/89680</guid><dc:creator><![CDATA[franziss]]></dc:creator><pubDate>Thu, 26 May 2011 11:51:48 GMT</pubDate></item></channel></rss>