[PyQt] Fwd: Mixin classes and PyQt4

Phil Thompson phil at riverbankcomputing.com
Mon Feb 10 18:43:11 GMT 2014


On 10-02-2014 6:16 pm, Baz Walter wrote:
> On 10/02/14 09:55, Martin Teichmann wrote:
>> I tried to write a mixin class for PyQt4 and, well, failed.
>> Here is the short version of what I did:
>>
>> ========================
>> from PyQt4.QtGui import QWidget, QApplication, QLabel
>>
>> class A(QWidget):
>>      def sizeHint(self):
>>          print('mixed in!', self.parent())
>>          return super().sizeHint()
>>
>> class B(A, QLabel):
>>      pass
>>
>> class C(QLabel, A):
>>      pass
>> ========================
>>
>
> Why not simply:
>
> class A(object):
>     def sizeHint(self):
>         print('mixed in!', self.parent())
>         return super().sizeHint()
>
> class B(A, QLabel):
>     pass
>
> class C(A, QLabel):
>     pass

That was my first reaction, but having to do...

class B(A, QLabel)

...rather than...

class B(QLabel, A)

...isn't nice.

Phil


More information about the PyQt mailing list