Label help
-
so i have a label with a gray background as a visualizer I want to make the label height the same size as the text so I want to bring the gray or the label size down to the point where the gray is just surrounding the time Any ideas?
@nick_d12 You can use https://doc.qt.io/qt-6/qfontmetrics.html to determine the height of the text and then set fixed height for the label.
-
@nick_d12 You can use https://doc.qt.io/qt-6/qfontmetrics.html to determine the height of the text and then set fixed height for the label.
-
@jsulm Hey thanks for the reply Unfortunately, for some reason that did not work I don't know if it is worth pointing out that I am using pyqt5 I am not sure if that changes anything, but I don't think so
-
@JonB ```
def get_font_metrics(size):
font = QFont("Nirmala UI Semilight", pointSize=size)
font_metrics = QFontMetrics(font)
text_height = font_metrics.height()
return text_heightI made this function to get the height of font them I use a fixed height based on the return value of this maybe I am using it wrong?
-
@jsulm Hey thanks for the reply Unfortunately, for some reason that did not work I don't know if it is worth pointing out that I am using pyqt5 I am not sure if that changes anything, but I don't think so
-
@JonB it works on text just fine however when it comes to numbers such as in the date not so much
@nick_d12 Please use code tags correctly, especially when posting Python code.
Is the font you're setting in QFont really the same used in the label? And what is the value get_font_metrics returns?
Also, "that did not work" is not a proper problem description. In what way it did not work? Is the calculated height to big or to small?