[PyQt] Size for hint label

Mads Ipsen madsipsen at gmail.com
Wed Jan 9 14:55:51 GMT 2013


Hi,

4-5 years I needed a widget with the following properties:

  * Display text incl. HTML
  * Text should be wrapped on several lines
  * When the widget is put into a layout, the height of the widget
    should be adjusted in such a way that the text exactly fits the
    widget geometry

This subwidget should be used in a layout to provide some detail on how 
the other GUI elements in the layout work but only consume a minimum 
space to display its content.

I thought this was an easy one - but each time I return to the challenge 
I always end by giving up.

The main problem is that the layout breaks down when heightForWidth() is 
implemented and a QSizePolicy with setHeightForWidth(True) is used. It 
can shrink to infinitely small. Apparently this is Qt bug.

Another approach is to call updateGeometry() when a resizeEvent() occurs 
and call setFixedHeight(h) using a width dependent height. But this also 
gives rise to some weird layout behavior.

If anybody has any good suggestions on how to approach this, please let 
me know.

I attach a small snippet that reproduces the layout resizing behavior.

Best regards,

Mads

-- 
+-----------------------------------------------------+
| Mads Ipsen                                          |
+----------------------+------------------------------+
| Gåsebæksvej 7, 4. tv |                              |
| DK-2500 Valby        | phone:          +45-29716388 |
| Denmark              | email:  mads.ipsen at gmail.com |
+----------------------+------------------------------+

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130109/527c1fcc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: height_for_width.py
Type: text/x-python
Size: 1290 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130109/527c1fcc/attachment.py>


More information about the PyQt mailing list