<?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[Text label with irregular shape?]]></title><description><![CDATA[<p dir="auto">Is there a simple way to format a textual label to follow an irregular border?</p>
<p dir="auto">Here is an example taken from the current UML standard (2.5.1) illustrating a comment note:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/d9b192ac-027a-4887-a5df-a5a5d7d1c0aa.png" alt="comment_original.png" class=" img-fluid img-markdown" /><br />
If I draw the text within the green rectangle in the following image, there is always the possibility that it will collide with the turned-down corner at the upper right:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/da3506e2-4ec9-4b0e-b6d7-3e9c3fa15fbf.png" alt="comment_green_rectangle.png" class=" img-fluid img-markdown" /><br />
However, is it possible to define a closed path as in the pink shape in the following image and have the text constrained to the enclosed area?<br />
<img src="https://ddgobkiprc33d.cloudfront.net/a6e93807-e087-485a-a785-8f240758fa09.png" alt="comment_pink_rectangle.png" class=" img-fluid img-markdown" /><br />
Of course, we have no way of knowing how the original image was created, but for such purposes there should be a way of automatically formatting any kind of text.</p>
<p dir="auto">If I constrain the text to the area of the rectangle whose width fits the distance between the left-hand border and the edge of the turned-down corner, it leaves too much space at the right of the rest of the text.</p>
<p dir="auto">What is the best way of approaching this?</p>
]]></description><link>https://forum.qt.io/topic/155191/text-label-with-irregular-shape</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Mar 2026 01:15:52 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/155191.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 09 Mar 2024 20:50:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Text label with irregular shape? on Sun, 10 Mar 2024 08:49:49 GMT]]></title><description><![CDATA[<p dir="auto">Thanks very much <a class="plugin-mentions-user plugin-mentions-a" href="/user/chris-kawa">@<bdi>Chris-Kawa</bdi></a> ... this is exactly what I was hoping for.</p>
]]></description><link>https://forum.qt.io/post/792700</link><guid isPermaLink="true">https://forum.qt.io/post/792700</guid><dc:creator><![CDATA[Robert Hairgrove]]></dc:creator><pubDate>Sun, 10 Mar 2024 08:49:49 GMT</pubDate></item><item><title><![CDATA[Reply to Text label with irregular shape? on Sat, 09 Mar 2024 22:24:10 GMT]]></title><description><![CDATA[<p dir="auto">You can use <a href="https://doc.qt.io/qt-6/qtextlayout.html" target="_blank" rel="noopener noreferrer nofollow ugc">QTextLayout</a>. You define line boxes and it breaks the text apart to fit into these boxes. The docs have an <a href="https://doc.qt.io/qt-6/qtextlayout.html#details" target="_blank" rel="noopener noreferrer nofollow ugc">example code</a> how to use it.</p>
<p dir="auto">For your particular example it's simple enough - just have the first line box a bit shorter and then all the other ones longer.</p>
<p dir="auto">For a general case of any shape it's similar, but you first have to find the boxes that fit into the shape. There's nothing in Qt (that I know) to do it for you, but the algorithm is well documented, as it's used e.g. in the CSS spec for the <a href="https://drafts.csswg.org/css-shapes-2/#propdef-shape-inside" target="_blank" rel="noopener noreferrer nofollow ugc">shape-inside</a> property. Basically you rasterize the shape into a grid and find the cell groups that don't intersect the shape, as described e.g. <a href="https://hansmuller-webkit.blogspot.com/2012/06/horizontal-box-polygon-intersection-for.html" target="_blank" rel="noopener noreferrer nofollow ugc">here</a> (there's a nice visualization at the bottom).</p>
]]></description><link>https://forum.qt.io/post/792685</link><guid isPermaLink="true">https://forum.qt.io/post/792685</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Sat, 09 Mar 2024 22:24:10 GMT</pubDate></item></channel></rss>