Question

How can I get the text margins for a QLineEdit?

Note the red lines in the screenshot, that's the margins I'm interested in:

enter image description here

I tried qDebug() << ui->lineEdit->textMargins(); for the edit box from the screenshot, but it printed QMargins(0, 0, 0, 0), even though the edit box does have margins.

Was it helpful?

Solution

Check paint event of QLineEdit. As you can see lots of stuff have effect on it.

Besides textMargins there are stuff which can have impact on values which you are looking for.

  1. used style (see line 1942)
  2. and font properties - see QFontMetrics::ascent and QFontMetrics::descent

The style value is most important and you have to find way to get this value (probably subclass is needed).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top