[PyQt] segfault on casting a QPaintDevice to a QWidget

Phil Thompson phil at riverbankcomputing.com
Mon Mar 16 17:32:39 GMT 2015


On 15/03/2015 10:13 pm, Wilbert Berendsen wrote:
> Friends,
> 
> I try this:
> 
> wilbert at sweelinck:~$ python  # (both 2 and 3)
> Python 2.7.8 (default, Oct 20 2014, 15:05:29)
> [GCC 4.9.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from PyQt4.QtGui import *
>>>> a = QApplication([])
>>>> w = QWidget()
>>>> import sip
>>>> p = sip.cast(w, QPaintDevice)
>>>> w1 = sip.cast(p, QWidget)
>>>> dir(w1)
> Segmentatiefout

...because casting to a more specific type with multiple inheritance has 
problems.

> This may look contrived, but I want to get the widget via the
> painter.paintEngine().paintDevice() inside the paint() method of
> QIconEngineV2, to adjust the icon based on what widget type it is
> drawn on.

If Python knows about the widget then paintDevice() should return it 
with type QWidget.

Phil


More information about the PyQt mailing list