Enable QLabel for compression, even if it truncates text

How can I get QLabel to resize even if it means truncating its containing text? I have a QLabel stretching the entire horizontal space of a widget. When setting up its text, I am sure that it is truncated correctly, i.e. Gets its FontMetrics and Width and uses metrics.elidedText ().

But when the user resizes the widget, the shortcut does not allow it to shrink further, as it truncates its text.

Any ideas how to solve this? The simplest solution, which, it seems to me, would be to somehow tell QLabel to always compress, and then catch the resize event and format the text correctly - I just don’t know how to make the first part (policies of different sizes do not help)

+8
qt qt4 pyqt pyqt4
source share
1 answer

Although you indicate that size policy policies did not help, setting a horizontal QLabel size policy for QSizePolicy::Ignored should tell the containing layout manager to ignore the minimum size hint from the label. An alternative would be to set the minimum horizontal size of QLabel to a non-zero value, for example 1. If none of them work, then there is something else interfering.

+8
source share

All Articles