Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable QLabel to shrink even if it truncates text

Tags:

qt

qt4

pyqt

pyqt4

How can I get a QLabel to be resized even if it means truncating its containing text? I have a QLabel stretching the whole horizontal space of a Widget. When setting its text I make sure it is correctly truncated, ie getting its FontMetrics and Width and using metrics.elidedText().

But when the user resizes the widget the Label doesn't allow it to shrink any further since it would truncate its text.

Any ideas how to solve this? The simplest solution I think would be to somehow tell the QLabel to always shrink and then catch the resize event and correctly format the text - I just have no idea how to do the first part (different size policies don't help)

like image 220
Voo Avatar asked Jul 17 '11 00:07

Voo


1 Answers

Although you mention that setting size policies didn't help, setting the QLabel's horizontal size policy to QSizePolicy::Ignored should tell the containing layout manager to ignore any minimum size hint from the label. An alternative would be to set the QLabel's minimum horizontal size to a non-zero value, like 1. If neither of these work then there is something else interfering.

like image 89
Arnold Spence Avatar answered Sep 21 '22 21:09

Arnold Spence