What is the concrete way to change the font size of a label to match the layout size its contained in through signal/slots?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
Below is a solution, for a
QLabel
, derived from the solution posted here: https://forum.qt.io/topic/36088/automatically-scale-text-in-qlabels/5.This consists in a reimplementation of the
resizeEvent
method where the font size of theQLabel
is updated according to the size of itscontentRect
. Note that thesizePolicy
of the Qlabel has to be set toIgnored
for this to work properly.Which results in:
Update - Optimization of resizeEvent :
Below is an optimized version of the
resizeEvent
method that should yield better performances. It drastically reduces the number of iteration required to find the optimal value of the font size. I haven't tested it extensively though.