[PyQt] QTextLayout.createLine crashes

Jérôme Laheurte jerome at jeromelaheurte.net
Mon Mar 27 17:12:24 BST 2017


> Le 27 mars 2017 à 17:45, David Boddie <david at boddie.org.uk> a écrit :
> 
> On Mon Mar 27 10:11:55 BST 2017, Jérôme Laheurte wrote:
> 
>> Hello. This smells like a bug; I was « porting » the ElidedLabel sample
>> when I stumbled upon it. The following code crashes with a SIGSEGV in
>> createLine() (Qt/PyQt 5.8.1, mac OS 10.11.6):
>> 
>> 
>> from PyQt5 import QtWidgets, QtGui
>> 
>> 
>> class TestWidget(QtWidgets.QWidget):
>>    def paintEvent(self, event):
>>        painter = QtGui.QPainter(self)
>>        layout = QtGui.QTextLayout('spam', painter.font())
>>        line = layout.createLine()
> 
> You need to call layout.beginLayout() before calling createLine(), then call
> endLayout() when you have finished. It's the same in PyQt4.

Ahah, that will teach me to dumbly convert hastily read C++ code to Python without knowing what I’m doing. Thanks.

Best regards
Jérôme Laheurte

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170327/97449276/attachment.sig>


More information about the PyQt mailing list