I am working on a PyQt5 project, but would be happy to read C++/Qt answer as well, because C++ solutions may work on Python too.
I have a MainWindow with a horizontal layout, and a QLabel in it.
My QLabel's size Policy is "Expanding", therefore all my window is filled by the QLabel.
However, the text displayed by my QLabel does not change its size. I would like the text to grow when the window grows, and be as big as possible, in the limit of the QLabel size.
I have heard of QWidget::adjustSize()
but could not figure out how to use it.
The option scaledContents
for my QLabel on QtDesigner does not do anything, so I guess it is only useful for when using pixmap.
For the moment, my solution is to reimplement the resizeEvent()
method of my window and change the font size of my label with setFont()
. But I think that there must be an easier solution. Moreover, my resizeEvent()
method is not very good because I make a linear relation between myWindowWidth* myWindowHeight
and myTextFontSize
, therefore when only myWindowWidth
increase, myTextFontSize
increases and forces myWindowHeight
to increase, which is bad.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…