[PyQt] Multiple inheritance with item views
apaku at gmx.de
Mon Feb 22 21:39:24 GMT 2010
On 22.02.10 21:09:28, Jugdish wrote:
> The reason I have BaseView inheriting from QAbstractItemView is because
> inside it I make calls like:
> and so on. These are all things that are common to both
> MyTreeView/MyTableView, and obviously wouldn't work if BaseView had no base
Sure they would, thats so nice about python being a dynamically typed
language - as long as self has that function during runtime it'll work.
And during runtime it does have that function because of subclassing
MyTableView from QTableView+BaseView (unless PyQt4 has a restriction).
Take this example:
print "Hi", self
class FooBar( Foo, Bar ):
print "me:", self
f = FooBar()
It'll just work.
> Any ideas of a better way to achieve this without duplicating code between
> the 2 views?
Avoiding code-duplication should only be done with subclassing if the
subclasses "make sense", i.e. if they'd also exist without wanting to
avoid the code-duplication. In other cases the duplicated code should
rather be put into some shared functions or the like.
Your object is to save the world, while still leading a pleasant life.
More information about the PyQt