[PyQt] Fwd: Mixin classes and PyQt4

Baz Walter bazwal at ftml.net
Wed Feb 12 21:55:12 GMT 2014


On 12/02/14 09:35, Martin Teichmann wrote:
> Hi Phil, Hi Baz, Hi List,
>
> I just wrote a patch as advertised earlier, which checks that the
> inheritance is correct and that noone attempts to inherit from more
> than one PyQt base class. It is based on the patch sent earlier.
> Maybe this is an improvement enough to put my patches in?

This actually only relates to multiple-inheritance. It should never be 
problem for true mixin classes.

The one genuine issue with mixins in PyQt, is that you cannot inherit 
custom signals.

In PySide, I can do this:

 >>> from PySide import QtCore, QtGui
 >>> app = QtGui.QApplication([])
 >>> class A(object):
...     sig = QtCore.Signal(int)
...
 >>> class B(A, QtGui.QLabel):
...     def __init__(self):
...         super(B, self).__init__()
...         self.sig.connect(self.bar)
...     def foo(self): self.sig.emit(42)
...     def bar(self, i): print(i)
...
 >>> b = B()
 >>> b.foo()
42

I understand that Qt itself doesn't allow this, but is there a technical 
reason why this is not possible in PyQt? There is a real, practical need 
for this functionality (code reuse), and its galling that PySide allows 
it but PyQt doesn't.

-- 
Regards
Baz Walter


More information about the PyQt mailing list