[PyKDE] how to pass Qt.WFlags?

Phil Thompson phil at riverbankcomputing.co.uk
Mon Mar 13 22:10:09 GMT 2006


On Sunday 12 March 2006 9:52 pm, Gerard Vermeulen wrote:
> Phil,
>
> this program:
>
> #!/usr/bin/env python
>
> import sys
> import PyQt4.Qt as Qt
>
> class MyMainWindow(Qt.QMainWindow):
>     def __init__(self):
>         print type(Qt.Qt.WA_QuitOnClose)
>         # this type must be an alias for a WFlags, isn't it??
>         Qt.QMainWindow.__init__(self, None, Qt.Qt.WA_QuitOnClose)
>
> if __name__ == '__main__':
>     app = Qt.QApplication(sys.argv)
>     demo = MyMainWindow()
>     demo.show()
>
> raises this exception:
>
> $ python bug.py
> <class 'PyQt4.QtCore.WidgetAttribute'>
> Traceback (most recent call last):
>   File "bug.py", line 14, in ?
>     demo = MyMainWindow()
>   File "bug.py", line 10, in __init__
>     Qt.QMainWindow.__init__(self, None, Qt.Qt.WA_QuitOnClose)
> TypeError: argument 2 of QMainWindow() has an invalid type
>
> Am I doing something wrong?

They are of different types. WA_QuitOnClose is an WidgetAttribute enum. Use 
QWidget.setAttribute() to set it.

Phil




More information about the PyQt mailing list