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

Alexander Dyagilev alervdvcw at gmail.com
Tue Apr 13 22:30:58 CEST 2021


Hello,

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:

enter image description here <https://i.stack.imgur.com/SZM6n.png>

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.

enter image description here <https://i.stack.imgur.com/omRiw.png>

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?

Here is the QML code for these two images:

importQtQuick2.12

importQtQuick.Window2.12

importQtQuick.Controls2.12

importQtQuick.Layouts1.12

Window{

width:640

height:480

visible:true

title:qsTr("HelloWorld")

propertystringmyText:"SOMETESTTEXT"

propertyintmyFontPixelSize:13

ColumnLayout

{

spacing:20

anchors.left:parent.left

anchors.top:parent.top

anchors.leftMargin:10

anchors.topMargin:10

RowLayout

{

spacing:5

Rectangle

{

color:"blue"

Layout.preferredWidth:13

Layout.preferredHeight:12

Layout.alignment:Qt.AlignVCenter

}

Label

{

text:"<ahref='https://bugreports.qt.io'>"+myText+"</a>"

font.pixelSize:myFontPixelSize

font.family:"Arial"

Layout.fillWidth:true

Layout.alignment:Qt.AlignVCenter

}

}

RowLayout

{

spacing:5

Rectangle

{

color:"blue"

Layout.preferredWidth:13

Layout.preferredHeight:12

Layout.alignment:Qt.AlignVCenter

}

Label

{

text:"<ahref='https://bugreports.qt.io'>"+myText+"</a>"

font.pixelSize:myFontPixelSize

font.family:"Arial"

Layout.fillWidth:true

Layout.alignment:Qt.AlignVCenter

Rectangle{anchors.fill:parent;color:"black";z:-1}

}

}

}

}





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210413/cca90b64/attachment.html>


More information about the Interest mailing list