[Interest] [External] Text: remove empty space at top or get its size

Alexander Dyagilev alervdvcw at gmail.com
Wed Apr 14 01:28:24 CEST 2021


Thanks for the response.

I don't see any suitable value in FontMetrics.

tightBoundingRect is helpful and can be used. But unfortunately, it does 
not take underline into account (i.e. it ignores 
FontMetrics.font.underline). I don't know if it's a bug or not. Also, 
it's very slow on Windows, as it stated in docs.


On 4/14/2021 12:12 AM, Murphy, Sean wrote:
>> I want to center vertically image and text. But when I'm trying to, it does not
>> look centered, because of an empty space at the top of the text.
>> What I mean is illustrated by this image:
>>
>> The blue rectangle looks a bit above the text. However, these two controls are
>> centered actually. The second image illustrates this by showing text's bounding rectangle.
>>
>> Is there any way to remove this few empty lines of pixels at the top in the text control?
>> Or at least somehow get its height so I can take this into account manually?
> Have you looked at font metrics (https://doc.qt.io/qt-5.12/qml-qtquick-fontmetrics.html)? I've never played around with the parts your concerned about specifically, but it looks like maybe your answer may lie somewhere in the ascent and/or tightBoundingRect() areas?
>
> Sean
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest


More information about the Interest mailing list