[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] HeightForWidth label
From: Mads Ipsen <madsipsen () gmail ! com>
Date: 2013-01-10 8:53:31
Message-ID: 50EE818B.7090606 () gmail ! com
[Download RAW message or body]
Dear Pete,
Thanks a lot for your input. To some extend its too bad that this
feature cannot be implemented in a proper fashion - especially when the
documentation of Qt tells you that it can.
Best regards,
Mads
On 09/01/2013 22:00, Hans-Peter Jansen wrote:
> Dear Mads,
>
> Am Mittwoch, 9. Januar 2013, 15:56:29 schrieb Mads Ipsen:
>> 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.
> Yes, been there, done that, and failed in similar ways.
>
> The best thing I could come up on this was:
>
> use a QTextBrowser for the text:
>
> self.aboutText.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
> self.aboutText.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
> self.aboutText.setLineWrapMode(QtGui.QTextEdit.NoWrap)
> self.aboutText.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
> self.aboutText.setHtml("...")
>
> w = self.aboutText.document().idealWidth()
> self.aboutText.document().setTextWidth(w)
> ds = self.aboutText.document().size()
> self.aboutText.setMinimumSize(int(ds.width() + 3), int(ds.height() + 3))
> self.aboutText.updateGeometry()
> self.layout().setSizeConstraint(QtGui.QLayout.SetFixedSize)
>
> with this, you can even provide clickable links (but disable openLinks prop):
>
> @QtCore.pyqtSignature("const QUrl &")
> def on_aboutText_anchorClicked(self, url):
> QtGui.QDesktopServices.openUrl(url)
>
> Maybe it gets you going..
>
> Cheers,
> Pete
> _______________________________________________
> PyQt mailing list PyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
--
+-----------------------------------------------------+
| Mads Ipsen |
+----------------------+------------------------------+
| Gåsebæksvej 7, 4. tv | |
| DK-2500 Valby | phone: +45-29716388 |
| Denmark | email: mads.ipsen@gmail.com |
+----------------------+------------------------------+
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic