[PyQt] PyQt4 flags processing

Phil Thompson phil at riverbankcomputing.com
Wed Sep 29 20:08:43 BST 2010


On Wed, 29 Sep 2010 20:27:37 +0200, "Hans-Peter Jansen" <hpj at urpla.net>
wrote:
> On Wednesday 29 September 2010, 18:22:18 Phil Thompson wrote:
>> On Wed, 29 Sep 2010 11:11:41 +0200, "Hans-Peter Jansen" <hpj at urpla.net>
>>
>> wrote:
>> > Hi Phil,
>> >
>> > I believe, that code like this ought to run correctly:
>> >
>> > from PyQt4 import QtCore, QtGui
>> >
>> > class Widget(QtGui.QWidget):
>> >     def __init__(self, parent = None, flags = 0):
>> >         super(Widget, self).__init__(parent, flags)
>> >
>> > app = QtGui.QApplication([])
>> > win = Widget()
>> > win.show()
>> > app.exec_()
>> >
>> > Now it results in:
>>
>> When you say "now" do you mean it used to behave differently?
> 
> Yes, IIRC. I have code like this from sip3/PyQt3 times:
> 
> class Plotter(QWidget):
>     def __init__(self, parent = None, name = "", flags = 0):
>         QWidget.__init__(self,  parent, name, flags | Qt.WNoAutoErase)
> 
> that ought to have worked..

WFlags in Qt3 was an unsigned int. It was changed in Qt4 precisely to
provide some type checking.

>> > [...]
>> >
>> >>>> win = Widget()
>> >
>> > Traceback (most recent call last):
>> >   File "<stdin>", line 1, in <module>
>> >   File "<stdin>", line 3, in __init__
>> > TypeError: QWidget(QWidget parent=None, Qt.WindowFlags flags=0):
>> > argument 2 has unexpected type 'int'
>> >
>> > Do we really need wrap the flags argument with
>> > QtCore.Qt.WindowFlags(flags) to make this work correctly?
>>
>> All you need to do is...
>>
>>     def __init__(self, parent=None, flags=QtCore.Qt.WindowFlags(0)):
>>
>> ...which seems reasonable to me.
> 
> I feared, you would say that ;-).
> 
> Sure, but it feels arkward, doesn't it? (Apart from being loquacious
_and_ 
> painful for users, that were indulged from C++ (which is a contradiction
> in 
> itself)).

I prefer the explicitness.

Phil


More information about the PyQt mailing list