<?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[Amount to adjust a rectangle]]></title><description><![CDATA[<p dir="auto">Assume that I have a selected Rectangle in image coordinates.</p>
<p dir="auto">To draw this I do:</p>
<pre><code>void SelectRect::paintEvent(QPaintEvent*)
{
    QPainter painter(this);
    QPen pen(Qt::red, 1.0);
    QRectF rect(imageView-&gt;imageToScreen(selectRect.normalized()));
    painter.setPen(pen);
    //
    // If there's actually a selected area
    //
    if (!rect.isEmpty())
    {
        painter.drawRect(rect
            .adjusted(0, 0, -1, -1));
</code></pre>
<p dir="auto">Which is correct for a pen width of 1.0.  If however the pen width is 3.0, what should the adjustment be (I don't think (0, 0, -3, -3) is correct)?</p>
<p dir="auto">Thanks<br />
D.</p>
]]></description><link>https://forum.qt.io/topic/138535/amount-to-adjust-a-rectangle</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 05:41:56 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/138535.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Aug 2022 16:23:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Amount to adjust a rectangle on Fri, 12 Aug 2022 09:19:24 GMT]]></title><description><![CDATA[<p dir="auto">Many thanks</p>
]]></description><link>https://forum.qt.io/post/724631</link><guid isPermaLink="true">https://forum.qt.io/post/724631</guid><dc:creator><![CDATA[Perdrix]]></dc:creator><pubDate>Fri, 12 Aug 2022 09:19:24 GMT</pubDate></item><item><title><![CDATA[Reply to Amount to adjust a rectangle on Fri, 12 Aug 2022 09:10:48 GMT]]></title><description><![CDATA[<p dir="auto">Ok, so basically you want the rectangle to grow inward. Like I said the width grows both ways so you just have to shift it inward i.e.</p>
<pre><code>float halfWidth = (pen.widthF() - 1.f) / 2.f;
</code></pre>
<p dir="auto">and then instead of</p>
<pre><code>painter.drawRect(rect.adjusted(0, 0, -1, -1));
</code></pre>
<p dir="auto">you do</p>
<pre><code>painter.drawRect(rect.adjusted(halfWidth , halfWidth , -halfWidth -1 , -halfWidth -1 ));
</code></pre>
<p dir="auto">It's floating point, so like I said - you might see some wobble for some widths due to imperfect rounding.</p>
]]></description><link>https://forum.qt.io/post/724630</link><guid isPermaLink="true">https://forum.qt.io/post/724630</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Fri, 12 Aug 2022 09:10:48 GMT</pubDate></item><item><title><![CDATA[Reply to Amount to adjust a rectangle on Fri, 12 Aug 2022 09:01:06 GMT]]></title><description><![CDATA[<p dir="auto">If the selection is e.g. (0,0,10,10), using the code above the drawn rectangle fits exactly inside the selection rectangle and encloses a rectangle (1, 1, 9, 9).</p>
<p dir="auto">For larger pen sizes I think I  would still want the drawn rectangle to fit exactly inside the selection rectangle.</p>
<p dir="auto">If the pen width were 2.0 I would want the drawn rectangle to enclose a rectangle (2, 2, 8, 8).</p>
<p dir="auto">If the pen size were 3.0 the enclosed rectangle should be (3, 3, 7, 7).</p>
<p dir="auto">I'm sure there's a good algorithm to express that but I can't figure it out right now.</p>
<p dir="auto">What's the normal convention for drawing a selection rect ?  Inside the selection, or outside, or directly on top of?</p>
<p dir="auto">Thanks<br />
David</p>
]]></description><link>https://forum.qt.io/post/724629</link><guid isPermaLink="true">https://forum.qt.io/post/724629</guid><dc:creator><![CDATA[Perdrix]]></dc:creator><pubDate>Fri, 12 Aug 2022 09:01:06 GMT</pubDate></item><item><title><![CDATA[Reply to Amount to adjust a rectangle on Thu, 11 Aug 2022 19:33:10 GMT]]></title><description><![CDATA[<p dir="auto">It depends on what result you're looking for. The line grows equally to both sides i.e. for the same rectangle and width 3.0 it's gonna be 1 px inward and 1 px outward from the line of width 1.0. if you want an outline you'll have to further adjust by <code>(width-1)/2</code>  outward , so <code>adjusted(-1,-1,0,0)</code> and to grow inward <code>adjusted(1,1,-2,-2)</code>.</p>
<p dir="auto">It's a little wobbly for even and fractional widths so it's best to use odd values.</p>
]]></description><link>https://forum.qt.io/post/724586</link><guid isPermaLink="true">https://forum.qt.io/post/724586</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Thu, 11 Aug 2022 19:33:10 GMT</pubDate></item></channel></rss>