[PyQt] QTextLayout.createLine crashes

David Boddie david at boddie.org.uk
Mon Mar 27 16:45:26 BST 2017


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.

David


More information about the PyQt mailing list