[Interest] Align text to top of Text

André Somers andre at familiesomers.nl
Tue Mar 28 21:38:22 CEST 2017



Sent from my phone, please excuse my brevity

> On 28 Mar 2017, at 21:14, Shantanu Tushar <shaan7in at gmail.com> wrote:
> 
> Hi Jason,
> 
> Thanks for the quick reply! Have you used the negative topPadding technique in practice? If yes did you use a fixed value or could you calculate it using QFontMetrics?

I have done something similar. I wrapped Text in a surrounding item and aliased basically all properties. Then I positioned the Text item inside this surrounding TightText item. Now that I think about it, padding might have worked too. 

You should calculate the offset. Note that Text allows (parts of) characters to be outside of the items box, as long as you don't enable clipping. I used a fixed letter to calculate how high the 'normal' characters are and adjusted the position accordingly. 

André
> 
> Cheers,
> 
>> On Wed, Mar 29, 2017 at 12:36 AM, Jason Allen <jasoncaryallen at gmail.com> wrote:
>> You are positioning the text and the topmost left edge correctly, but also consider that depending on a font or character typed, not all characters take up the full available height.
>> 
>> Characters like ` ' | / \ and " are sometimes above the height of latin letters, as are capital-case letters with accents like É vs E, Ñ vs N, or U vs Ü. See below, using your exact code with additional characters. Note that `, Ü, and Ñ are indeed flush with/touching the topmost edge:
>> <Screen Shot 2017-03-28 at 3.03.01 PM.png>
>> If it's a static label that you're positioning and KNOW won't contain accents or above-letter-height character, use negative topPadding to nudge it higher.
>> 
>> If it's dynamic text that may contain an above-letter-height character, consider leaving it be as-is, or it might clip on the top edge.
>> 
>> I hope this helps!
>> Best regards,
>> Jason
>> 
>> 
>> 
>> Jason Allen  
>> m: 703-868-5306
>> w: www.jasoncaryallen.com
>>    
>> 
>>> On Tue, Mar 28, 2017 at 2:51 PM, Shantanu Tushar <shaan7in at gmail.com> wrote:
>>> Hi,
>>> 
>>> I'm trying to align some text in a Text so that it exactly touches the left and top edges of the Text item. With the following-
>>> 
>>> Rectangle {
>>>     anchors { fill: parent; margins: 5 }
>>>     border { width: 1; color: "red" }
>>> 
>>>     Text {
>>>         anchors.fill: parent
>>> 
>>>         topPadding: 0
>>>         verticalAlignment: Qt.AlignTop
>>>         text: "HELLO WORLD"
>>>     }
>>> }
>>> 
>>> I am able to get the following result-
>>> 
>>> 
>>> 
>>> As you can see there is still space between the text and the topmost edge of the Text. How do I eliminate this space?
>>> 
>>> Cheers,​
>>> 
>>> -- 
>>> Shantanu Tushar    (UTC +0530)
>>> shantanu.io
>>> 
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>> 
>> 
> 
> 
> 
> -- 
> Shantanu Tushar    (UTC +0530)
> shantanu.io
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170328/64b8bb08/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot_20170329_001801.png
Type: image/png
Size: 1763 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170328/64b8bb08/attachment.png>


More information about the Interest mailing list