Issue
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_()
Solution
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_()
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.