<?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[QGraphicstextitem dynamic resize and changing top-left position of item]]></title><description><![CDATA[<p dir="auto">For resizing QGraphicsRectItem and QGraphicsEllipseItem, setRect() function is available to resize as well as change location of the item (top-left corner of item).</p>
<p dir="auto">class BoundingBoxSetter<br />
{<br />
public:<br />
virtual void operator()(QGraphicsItem* item, const QRectF&amp; rect) = 0;<br />
};</p>
<p dir="auto">class RectResizer : public BoundingBoxSetter<br />
{<br />
public:<br />
virtual void operator()(QGraphicsItem* item, const QRectF&amp; rect)<br />
{<br />
QGraphicsRectItem* rectItem = dynamic_cast&lt;QGraphicsRectItem*&gt;(item);</p>
<pre><code>    if (rectItem)
    {
        rectItem-&gt;setRect(rect);
    }
}
</code></pre>
<p dir="auto">};</p>
<p dir="auto">In QGraphicsTextItem, only setTextWidth() is available, which can only modify width. If i perform resize from top-left corner, along with width change, top-left position also changes. Then how do i move QGraphicsTextItem to new position ?</p>
<p dir="auto">class TextResizer : public BoundingBoxSetter<br />
{<br />
public:<br />
virtual void operator()(QGraphicsItem* item, const QRectF&amp; rect)<br />
{<br />
QGraphicsTextItem* textItem = dynamic_cast&lt;QGraphicsTextItem*&gt;(item);</p>
<pre><code>    if (textItem)
    {
        textItem-&gt;setTextWidth(rect.width());
    }
}
</code></pre>
<p dir="auto">};</p>
]]></description><link>https://forum.qt.io/topic/140441/qgraphicstextitem-dynamic-resize-and-changing-top-left-position-of-item</link><generator>RSS for Node</generator><lastBuildDate>Mon, 15 Jun 2026 14:55:06 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/140441.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 31 Oct 2022 14:18:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QGraphicstextitem dynamic resize and changing top-left position of item on Wed, 02 Nov 2022 14:31:38 GMT]]></title><description><![CDATA[<p dir="auto">Thanks @JonB. I am able to resize QGraphicsTextItem in all directions by subclass QGraphicsTextItem and override function QRectF QGraphicsTextItem::boundingRect() const</p>
<p dir="auto">But, on resize, even though boundingbox is large enough to show text but text becomes hidden. Text visibility becomes inconsistent. I started to look into QTextDocument pointer returned from document() function. I think in QTextDocument also may need some changes for bounding box. Is this approach correct or you have any different idea ?</p>
]]></description><link>https://forum.qt.io/post/734840</link><guid isPermaLink="true">https://forum.qt.io/post/734840</guid><dc:creator><![CDATA[Sridharan]]></dc:creator><pubDate>Wed, 02 Nov 2022 14:31:38 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicstextitem dynamic resize and changing top-left position of item on Wed, 02 Nov 2022 09:04:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sridharan">@<bdi>Sridharan</bdi></a> said in <a href="/post/734777">QGraphicstextitem dynamic resize and changing top-left position of item</a>:</p>
<blockquote>
<p dir="auto">Is there any function in QGraphicsTextItem, QTextDocument or QAbstractTextDocumentLayout which can change bounding-rect x and y values ?</p>
</blockquote>
<p dir="auto">Is that what you question is?  Then, yes, subclass <code>QGraphicsTextItem</code> and override <a href="https://doc.qt.io/qt-6/qgraphicstextitem.html#boundingRect" target="_blank" rel="noopener noreferrer nofollow ugc">QRectF QGraphicsTextItem::boundingRect() const</a> to return whatever you want.  It has always been the case that you can do do this for any <code>QGraphicsItem</code> if you need to specify a bounding rectangle different from the shape's rectangle.</p>
]]></description><link>https://forum.qt.io/post/734812</link><guid isPermaLink="true">https://forum.qt.io/post/734812</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 02 Nov 2022 09:04:54 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicstextitem dynamic resize and changing top-left position of item on Wed, 02 Nov 2022 03:38:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Hi, I don't expect text to be bound within rectangle. In QGraphicsTextItem bounding-rect 'x' and 'y' value is always 0, 0. I am only able to change bounding-rect width using setTextWidth(). Is there any function in QGraphicsTextItem, QTextDocument or QAbstractTextDocumentLayout which can change bounding-rect x and y values ?</p>
]]></description><link>https://forum.qt.io/post/734777</link><guid isPermaLink="true">https://forum.qt.io/post/734777</guid><dc:creator><![CDATA[Sridharan]]></dc:creator><pubDate>Wed, 02 Nov 2022 03:38:24 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicstextitem dynamic resize and changing top-left position of item on Tue, 01 Nov 2022 20:03:07 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">There's no direct equivalent. You have <a href="https://doc.qt.io/qt-6/qgraphicstextitem.html#setTextWidth" target="_blank" rel="noopener noreferrer nofollow ugc">setTextWidth</a> that allows you to influence that dimension and the height will be adapted.</p>
<p dir="auto">If you want more control like "forcing the text within the bound of a particular rectangle, you'll have to implement that yourself.</p>
]]></description><link>https://forum.qt.io/post/734747</link><guid isPermaLink="true">https://forum.qt.io/post/734747</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 01 Nov 2022 20:03:07 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicstextitem dynamic resize and changing top-left position of item on Tue, 01 Nov 2022 05:46:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a></p>
<p dir="auto">Let's say a QGraphicsRectItem is at (x,y) position. When QGraphicsRectItem gets resized, i get new bounding box value. This boundingbox value is given to setRect() of QGraphicsRectItem, to make it larger/smaller. I don't change (x,y) position of the rectangle.</p>
<p dir="auto">Assume i resize using top-left corner of QGraphicsRectItem. In this case, position of item changes along with resize. Here also, i can set boundingbox value to setRect() function which resize and changes position of item.</p>
<p dir="auto">I want QGraphicsRectItem setRect() equivalent for QGraphicsTextItem</p>
]]></description><link>https://forum.qt.io/post/734679</link><guid isPermaLink="true">https://forum.qt.io/post/734679</guid><dc:creator><![CDATA[Sridharan]]></dc:creator><pubDate>Tue, 01 Nov 2022 05:46:59 GMT</pubDate></item><item><title><![CDATA[Reply to QGraphicstextitem dynamic resize and changing top-left position of item on Mon, 31 Oct 2022 15:46:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sridharan">@<bdi>Sridharan</bdi></a> said in <a href="/post/734608">QGraphicstextitem dynamic resize and changing top-left position of item</a>:</p>
<blockquote>
<p dir="auto">Then how do i move QGraphicsTextItem to new position ?</p>
</blockquote>
<p dir="auto">I don't really understand what you are asking, but every graphics item inherits void <a href="https://doc.qt.io/qt-6/qgraphicsitem.html#setPos" target="_blank" rel="noopener noreferrer nofollow ugc">QGraphicsItem::setPos(const QPointF &amp;pos)</a>.</p>
]]></description><link>https://forum.qt.io/post/734623</link><guid isPermaLink="true">https://forum.qt.io/post/734623</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 31 Oct 2022 15:46:45 GMT</pubDate></item></channel></rss>