[Interest] Align text to top of Text

Shantanu Tushar shaan7in at gmail.com
Tue Mar 28 21:14:45 CEST 2017


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?

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:
> [image: Inline image 1]
> 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 <070386%2085306>*w: www.jasoncaryallen.com
>   <https://twitter.com/jasonallen127>
> <https://www.linkedin.com/in/jasonallen127>
>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170329/1e2fb067/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/20170329/1e2fb067/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2017-03-28 at 3.03.01 PM.png
Type: image/png
Size: 11688 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170329/1e2fb067/attachment-0001.png>


More information about the Interest mailing list