Reputation: 19379
The code below creates a single QLineEdit with its font size set to 9. I would like to make sure there is no spacing between the text and the edge of the LineEdit.
What attribute controls the mentioned spacing?
from PyQt5.QtWidgets import *
app = QApplication(list())
line = QLineEdit()
font = line.font()
font.setPointSize(9)
line.setFont(font)
line.show()
app.exec_()
Upvotes: 4
Views: 1792
Reputation: 244291
The only way that space does not appear is that the height of the QLineEdit is fixed, and to calculate that height QFontMetrics should be used:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
app = QApplication(list())
line = QLineEdit()
font = line.font()
font.setPointSize(9)
line.setFont(font)
fm = QFontMetrics(line.font())
line.setFixedHeight(fm.height())
line.show()
app.exec_()
Upvotes: 2