[PyQt] Multiple inheritance with item views

Jugdish jugdizh at gmail.com
Mon Feb 22 19:45:31 GMT 2010


I have my own subclasses of QTreeView and QTableView, called MyTableView and
MyTreeView. There is a lot of code that is common between my 2 classes, so
to avoid having tons of duplicate code, I was thinking of having a base
class derived from QAbstractItemView that they both derive from. This
results in multiple inheritance. I know that the PyQt4 docs say that
inheriting from multiple PyQt classes is not supported, but the following
bit of code seems to work ok. I'm just wondering what sort of problems I
could run into using this approach...

########################################
from PyQt4 import *

class BaseView(QAbstractItemView):

    def setModel(self, model):
        # do stuff common to MyTableView/MyTreeView here...
        pass

class MyTableView(QTableView, BaseView):

    def setModel(self, model):
        QTableView.setModel(self, model)
        BaseView.setModel(self, model)

class MyTreeView(QTreeView, BaseView):

    def setModel(self, model):
        QTreeView.setModel(self, model)
        BaseView.setModel(self, model)
########################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100222/01ad62e7/attachment.html>


More information about the PyQt mailing list