[PyQt] Old problem with overriding QtGui.Qstyle.polish метод.

Phil Thompson phil at riverbankcomputing.com
Wed Apr 23 12:20:25 BST 2008


On Wednesday 23 April 2008, Igor Prischepoff wrote:
> Hello, experts.
> Can anyone please explain why my little app is crashing?
> I'm doing anything wrong here?
> Please see code below (also as attached file): generally I'm trying to
> create
> my own style based on standard styles which comes with qt.
> ==================================
> import sys
> from PyQt4 import QtCore, QtGui
> # testing abstract style which comes with pyqt
> # it crashes too. :(
> class AbstractStyle(QtGui.QStyle):
>     def __init__(self,usecols=False):
>         super(QtGui.QStyle,self).__init__()
>         print "__init__ ok"
>     def polish(self,args):
>         print "polish started..."
>         print "commenting out 'polish' method will prevent crush"
>         print "now we going to crash :("
>
>
> class WidgetGallery(QtGui.QWidget):
>     def __init__(self, parent=None):
>         QtGui.QWidget.__init__(self, parent)
> if __name__ == "__main__":
>     app = QtGui.QApplication(sys.argv)
>     QtGui.QApplication.setStyle(AbstractStyle())
>     gallery = WidgetGallery()
>     gallery.show()
>     sys.exit(app.exec_())
>
>
> ===========================
> Info: winxp, pyqt 4.3.3 python 2.5
> Can anyone check this script with current pyqt snapshot?
> May be this problem is fixed and I should rebuild my pyqt up-to-date ?

I don't see how you can expect this to work. PyQt will provide default 
implementations for the missing abstract methods, but there is no way those 
implementations can be expected to do "the right thing". You need to provide 
Python implementations of all QStyle's abstract methods.

Note that there is a bug in SIP (fixed in the snapshot) that means that the 
exception telling you need to provide a Python implementation doesn't get 
displayed to stdout.

Phil


More information about the PyQt mailing list