Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the text margins of a QLineEdit

Tags:

c++

qt

qlineedit

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.

like image 866
sashoalm Avatar asked Apr 16 '14 07:04

sashoalm


1 Answers

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).

like image 145
Marek R Avatar answered Oct 17 '22 03:10

Marek R