QTextLayout.createLine crashes

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

QTextLayout.createLine crashes

Jérôme Laheurte-2
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()


app = QtWidgets.QApplication([])
win = TestWidget()
win.show()
win.raise_()
app.exec_()

I tried keeping a reference on the string and the font (and creating my own font), same result every time. Any idea ?

Best regards
Jérôme Laheurte


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: QTextLayout.createLine crashes

Phil Thompson-5
On 27 Mar 2017, at 10:11 am, Jérôme Laheurte <[hidden email]> 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()
>
>
> app = QtWidgets.QApplication([])
> win = TestWidget()
> win.show()
> win.raise_()
> app.exec_()
>
> I tried keeping a reference on the string and the font (and creating my own font), same result every time. Any idea ?

A C++ version seems to behave in the same way.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QTextLayout.createLine crashes

Jérôme Laheurte-2

Le 27 mars 2017 à 14:28, Phil Thompson <[hidden email]> a écrit :

On 27 Mar 2017, at 10:11 am, Jérôme Laheurte <[hidden email]> 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):

A C++ version seems to behave in the same way.

Ah, a Qt bug, not PyQt. I’ll file a bug report then. Thanks!

Best regards
Jérôme Laheurte


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: QTextLayout.createLine crashes

David Boddie
In reply to this post by Jérôme Laheurte-2
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
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QTextLayout.createLine crashes

Jérôme Laheurte-2

> Le 27 mars 2017 à 17:45, David Boddie <[hidden email]> 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


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

signature.asc (859 bytes) Download Attachment