<?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[Fixed Text Width in QGraphicsScene]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">Im trying to draw a text with fixed width in a QGraphicsScene....<br />
I tried with all the few options like painter.drawText() and painter.drawPath() ..<br />
With this options i can able to draw the text in a QGraphicsScene but the text seems to be in expanding state when we zoom In and in collapsing state when we zoom out .<br />
What i want is , when ever I zoom in or out the text should have a fixed width  from the                    beginning stage .<br />
SUGGESTIONS WILL BE HIGHLY APPRECIATED</p>
]]></description><link>https://forum.qt.io/topic/73083/fixed-text-width-in-qgraphicsscene</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Apr 2026 13:16:27 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/73083.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 07 Nov 2016 10:14:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fixed Text Width in QGraphicsScene on Wed, 09 Nov 2016 17:00:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/keksi-venksi">@<bdi>keksi-venksi</bdi></a> ... I cannot give you exact code for proprietary reasons but here is the general idea of what I am saying...</p>
<p dir="auto">painter-&gt;save ()</p>
<p dir="auto">QTransform trans = painter-&gt;transform ();<br />
double currentScale = extractScale (trans); // Write function to extract the scale portion of the transform<br />
double newScale = originalScale / currentScale;<br />
trans.scale (newScale, newScale); // This may need to be scaled about the origin of the object so the text<br />
// stays with the object<br />
// eg. scaleAbout (invScale, originPt);<br />
painter-&gt;setTransform (trans);        // Now painter has a transform that has the scale removed<br />
// TODO: draw your text<br />
painter-&gt;restore ();</p>
<p dir="auto">Scaling about points can be found in Computer Graphics Principles and Practice by Foley,VanDam,Feiner, and Hughes pages 208-210.</p>
<p dir="auto">Since transformations are orthogonal, scales are found along the diagonal. If rotations are involved, the scales are componentized,</p>
]]></description><link>https://forum.qt.io/post/358745</link><guid isPermaLink="true">https://forum.qt.io/post/358745</guid><dc:creator><![CDATA[Buckwheat]]></dc:creator><pubDate>Wed, 09 Nov 2016 17:00:23 GMT</pubDate></item><item><title><![CDATA[Reply to Fixed Text Width in QGraphicsScene on Tue, 08 Nov 2016 10:21:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/buckwheat">@<bdi>Buckwheat</bdi></a> @m-sue</p>
<p dir="auto">Thanks for your reply ...</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/buckwheat">@<bdi>Buckwheat</bdi></a></p>
<p dir="auto">"I have found, you can use inverse scaling on the object. Take a snapshot of the transformations scale when you start. From then after, apply an inverse scale on the object using save and restore like @m-sue presented. You will most likely have to scale "about" the location to apply the inverse scale."</p>
<p dir="auto">Can you explain this point with some codes Please</p>
]]></description><link>https://forum.qt.io/post/358459</link><guid isPermaLink="true">https://forum.qt.io/post/358459</guid><dc:creator><![CDATA[keksi venksi]]></dc:creator><pubDate>Tue, 08 Nov 2016 10:21:27 GMT</pubDate></item><item><title><![CDATA[Reply to Fixed Text Width in QGraphicsScene on Mon, 07 Nov 2016 16:07:33 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I don't think ignoring is a good solution as it will ignore translations and rotations too and lose any object associations that are from the beginning.</p>
<p dir="auto">I have found, you can use inverse scaling on the object. Take a snapshot of the transformations scale when you start. From then after, apply an inverse scale on the object using save and restore like @m-sue presented. You will most likely have to scale "about" the location to apply the inverse scale.</p>
<p dir="auto">Another idea is to map the text location at the current transformation to the screen, setup the transformation as @m-sue suggested and then draw the text at the screen location.</p>
<p dir="auto">Both these suggestions should help you move the text around. If you do not want to move the text (ie a Title, Legend, etc) then the QGraphicsScene::drawForeground (...) and QGraphicsScene::drawBackground (...) will suffice with a cleared transformation.</p>
]]></description><link>https://forum.qt.io/post/358338</link><guid isPermaLink="true">https://forum.qt.io/post/358338</guid><dc:creator><![CDATA[Buckwheat]]></dc:creator><pubDate>Mon, 07 Nov 2016 16:07:33 GMT</pubDate></item><item><title><![CDATA[Reply to Fixed Text Width in QGraphicsScene on Mon, 07 Nov 2016 15:37:28 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
when you zoom, the paint device's transform is probably changed before it enters the drawBackground virtual function. So probably you can save the transform, reset it, then draw your text and at last restore the transform for use in the other virtual functions, like:</p>
<pre><code>painter-&gt;save();
painter-&gt;setTransform(QTransform());
//draw text
painter-&gt;restore();
</code></pre>
<p dir="auto">-Michael.</p>
]]></description><link>https://forum.qt.io/post/358335</link><guid isPermaLink="true">https://forum.qt.io/post/358335</guid><dc:creator><![CDATA[m.sue]]></dc:creator><pubDate>Mon, 07 Nov 2016 15:37:28 GMT</pubDate></item><item><title><![CDATA[Reply to Fixed Text Width in QGraphicsScene on Mon, 07 Nov 2016 15:00:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/schrodingersgat">@<bdi>SchrodingersGat</bdi></a></p>
<p dir="auto">Hi...<br />
Thanks for your reply ...</p>
<p dir="auto">Hope its a good solution ..</p>
<p dir="auto">The problem in my case is that in my app there are N no of items already  present in the QGraphicsScene . Also according to the requirements , I should draw the text seperately with out disturbing the items present in the scene .<br />
So I drawn the text in drawBackground() method of my scene .... Want some help for drawing the text through painter</p>
]]></description><link>https://forum.qt.io/post/358327</link><guid isPermaLink="true">https://forum.qt.io/post/358327</guid><dc:creator><![CDATA[keksi venksi]]></dc:creator><pubDate>Mon, 07 Nov 2016 15:00:17 GMT</pubDate></item><item><title><![CDATA[Reply to Fixed Text Width in QGraphicsScene on Mon, 07 Nov 2016 13:08:24 GMT]]></title><description><![CDATA[<p dir="auto">Sounds like you want to set the QGraphicsItem::ItemIgnoresTransformations attribute?</p>
<p dir="auto">See <a href="http://doc.qt.io/qt-5/qgraphicsitem.html#setFlags" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qgraphicsitem.html#setFlags</a></p>
]]></description><link>https://forum.qt.io/post/358309</link><guid isPermaLink="true">https://forum.qt.io/post/358309</guid><dc:creator><![CDATA[SchrodingersGat]]></dc:creator><pubDate>Mon, 07 Nov 2016 13:08:24 GMT</pubDate></item></channel></rss>