[Interest] Align text to top of Text

Jason Allen jasoncaryallen at gmail.com
Tue Mar 28 21:06:52 CEST 2017


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*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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170328/198c252b/attachment.html>
-------------- 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/20170328/198c252b/attachment.png>
-------------- 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/198c252b/attachment-0001.png>


More information about the Interest mailing list