I think the multiple inheritance route is just fine, to consider your abstract 
class as a mixin. The signal support is not a problem, since it will be 
processed as part of the QObject's metaclass. 
It's not legal to inherit from multiple QObjects, and you would see this when 
you try and call the constructor on both, which means it doesn't even really 
make sense to use a QObject as the base type of your mixin. 

class Abstract(QtGui.QWidget):
    pass

class Imp(QtGui.QLineEdit, Abstract):    
    def __init__(self):
        QtGui.QLineEdit.__init__(self)
        # Abstract.__init__(self) # <-- not legal
        # RuntimeError: You can't initialize an object twice!

Just use object or some other non-qt type. And the naming scheme of 
AbstractMixin, to me, indicates that it is to be used as a mixin and doesn't 
have a custom constructor. 

But, the addition of your own metaclass to the mixin will result in a conflict 
like this:

TypeError: Error when calling the metaclass bases
    metaclass conflict: the metaclass of a derived class must be a (non-strict) 
subclass of the metaclasses of all its bases

I've actually used this python recipe to support Qt mixins that have a 
metaclass and it worked great:
http://code.activestate.com/recipes/204197-solving-the-metaclass-conflict/



On Oct 27, 2013, at 2:25 AM, Marcus Ottosson wrote:

> This is more of a general programming question, but I figured it applies to 
> Qt programming in particular and I keep encountering it without finding any 
> nice enough solution.
> 
> I usually write an abstract interface for a set of classes and put 
> dependencies on the interface rather than their implementations. 
> 
> When subclassing QWidget however, how can you make an interface for 
> subclasses of an already implemented class? Is multiple inheritance a good 
> idea in this scenario?
> 
> Currently, I'm writing the interface as a subclass of QWidget, is this a good 
> way?
> 
> Thanks,
> Marcus
> 
> 
> -- 
> Marcus Ottosson
> [email protected]
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBL_NwPBZrMhf12FEROVPnBV_8%2B8fAqyZ2OKXqsTabujw%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/78B20000-CC99-4A5F-9059-A287D7B0419E%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to