<?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[Create a square in a scene with RubberBandDrag]]></title><description><![CDATA[<p dir="auto">Hello to everyone.</p>
<p dir="auto">First of all thanks a lot for reading this post and being able to help.</p>
<p dir="auto">I have an Scene where I would like to add a square item (polygon) just with RubberBandDrag mode.</p>
<p dir="auto">So user clicks on scene and drag mouse and when users releases mouse then add the polygon.</p>
<p dir="auto">How can I do that? thanks.</p>
]]></description><link>https://forum.qt.io/topic/69497/create-a-square-in-a-scene-with-rubberbanddrag</link><generator>RSS for Node</generator><lastBuildDate>Fri, 12 Jun 2026 01:19:50 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/69497.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 21 Jul 2016 08:08:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Create a square in a scene with RubberBandDrag on Tue, 26 Jul 2016 13:24:14 GMT]]></title><description><![CDATA[<p dir="auto">A Stack Trace would help.</p>
<p dir="auto">What are you doing with your rectangle variable ?<br />
Is it deleted anywhere ?</p>
]]></description><link>https://forum.qt.io/post/339350</link><guid isPermaLink="true">https://forum.qt.io/post/339350</guid><dc:creator><![CDATA[euchkatzl]]></dc:creator><pubDate>Tue, 26 Jul 2016 13:24:14 GMT</pubDate></item><item><title><![CDATA[Reply to Create a square in a scene with RubberBandDrag on Fri, 22 Jul 2016 09:52:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/devopia53">@<bdi>Devopia53</bdi></a> said:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alvaros">@<bdi>AlvaroS</bdi></a></p>
<p dir="auto">Hi.</p>
<blockquote>
<p dir="auto">I have an Scene where I would like to add a square item (polygon) just with RubberBandDrag mode.<br />
So user clicks on scene and drag mouse and when users releases mouse then add the polygon</p>
</blockquote>
<p dir="auto">something like this:</p>
<pre><code>drawRect = QRectF(0, 0, 0, 0);
connect(ui-&gt;graphicsView, &amp;QGraphicsView::rubberBandChanged,
        [&amp;](QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint){
    if (rubberBandRect.isNull()) {
        ui-&gt;graphicsView-&gt;scene()-&gt;addRect(drawRect);
        drawRect = QRectF(0, 0, 0, 0);            
    }
    else
        drawRect = QRectF(fromScenePoint, toScenePoint);
});
</code></pre>
</blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> said:</p>
<blockquote>
<p dir="auto">Hi<br />
no sample for rubberband. sadly</p>
<p dir="auto">Maybe this is interesting?<br />
<a href="http://www.walletfox.com/course/qgraphicsitemruntimedrawing.php" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.walletfox.com/course/qgraphicsitemruntimedrawing.php</a></p>
</blockquote>
<p dir="auto">Hello again. i have just figured it out the solution and it is the next:</p>
<pre><code>    if (check_generate_boxes_button == 0){
        ui-&gt;graphicsView-&gt;blockSignals(false);
        connect(ui-&gt;graphicsView, &amp;QGraphicsView::rubberBandChanged,
                [&amp;](QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint){
            if (rubberBandRect.isNull()) {
                rectangle = ui-&gt;graphicsView-&gt;scene()-&gt;addRect(drawRect);
                std::cout &lt;&lt; "estoy en if" &lt;&lt; std::endl;
                drawRect = QRectF(0, 0, 0, 0);
                rectangle-&gt;setFlag(QGraphicsRectItem::ItemIsSelectable, true);
                rectangle-&gt;setCursor(Qt::PointingHandCursor);
            }
            else{
                drawRect = QRectF(fromScenePoint, toScenePoint);
                std::cout &lt;&lt; "estoy en ELSE DEL if" &lt;&lt; std::endl;
            }

        });
        check_generate_boxes_button = 1;
    }

    else{
        ui-&gt;graphicsView-&gt;blockSignals(true);
        check_generate_boxes_button = 0;
    }
</code></pre>
<p dir="auto">I would like that the rectangle is selectable. It does not give me an error but when I select the rectangle that I define the program is unexpectedly finish.</p>
<p dir="auto">Does anyone know why?</p>
<p dir="auto">thanks!!!</p>
]]></description><link>https://forum.qt.io/post/338888</link><guid isPermaLink="true">https://forum.qt.io/post/338888</guid><dc:creator><![CDATA[AlvaroS]]></dc:creator><pubDate>Fri, 22 Jul 2016 09:52:56 GMT</pubDate></item><item><title><![CDATA[Reply to Create a square in a scene with RubberBandDrag on Fri, 22 Jul 2016 08:11:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/devopia53">@<bdi>Devopia53</bdi></a> Thanks a lot my friend. It works.</p>
<p dir="auto">Now, how can i disconnect it??<br />
Because I would like to connect it when I press a button and when I press the same button again to disconnect it.</p>
<p dir="auto">Thanks again!</p>
]]></description><link>https://forum.qt.io/post/338869</link><guid isPermaLink="true">https://forum.qt.io/post/338869</guid><dc:creator><![CDATA[AlvaroS]]></dc:creator><pubDate>Fri, 22 Jul 2016 08:11:50 GMT</pubDate></item><item><title><![CDATA[Reply to Create a square in a scene with RubberBandDrag on Thu, 21 Jul 2016 11:27:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alvaros">@<bdi>AlvaroS</bdi></a></p>
<p dir="auto">Hi.</p>
<blockquote>
<p dir="auto">I have an Scene where I would like to add a square item (polygon) just with RubberBandDrag mode.<br />
So user clicks on scene and drag mouse and when users releases mouse then add the polygon</p>
</blockquote>
<p dir="auto">something like this:</p>
<pre><code>drawRect = QRectF(0, 0, 0, 0);
connect(ui-&gt;graphicsView, &amp;QGraphicsView::rubberBandChanged,
        [&amp;](QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint){
    if (rubberBandRect.isNull()) {
        ui-&gt;graphicsView-&gt;scene()-&gt;addRect(drawRect);
        drawRect = QRectF(0, 0, 0, 0);            
    }
    else
        drawRect = QRectF(fromScenePoint, toScenePoint);
});
</code></pre>
]]></description><link>https://forum.qt.io/post/338721</link><guid isPermaLink="true">https://forum.qt.io/post/338721</guid><dc:creator><![CDATA[Devopia53]]></dc:creator><pubDate>Thu, 21 Jul 2016 11:27:51 GMT</pubDate></item><item><title><![CDATA[Reply to Create a square in a scene with RubberBandDrag on Thu, 21 Jul 2016 11:11:27 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
no sample for rubberband. sadly</p>
<p dir="auto">Maybe this is interesting?<br />
<a href="http://www.walletfox.com/course/qgraphicsitemruntimedrawing.php" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.walletfox.com/course/qgraphicsitemruntimedrawing.php</a></p>
]]></description><link>https://forum.qt.io/post/338718</link><guid isPermaLink="true">https://forum.qt.io/post/338718</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 21 Jul 2016 11:11:27 GMT</pubDate></item></channel></rss>