[PyKDE] PyQT/sip overloaded inheritance issue.

Toby Sargeant t.sargeant at inpharmatica.co.uk
Fri Jun 1 10:34:00 BST 2001

I've come across an interesting issue which has a workaround in python, but
which is, i think, worth mentioning.

QScrollView defines a virtual function

drawContents(QPainter *,int,int,int,int)

QScrollView also inherits from QFrame, which defines

drawContents(QPainter *)

If you derive from QScrollView in python, and implement the 6 argument version
of drawContents, you catch *both* the call to QFrame::drawContents, and the
call to QScrollView::drawContents, resulting in the following exception:

TypeError: drawContents() takes exactly 6 arguments (2 given)

as well as a successful call to the implementation of drawContents that the
python derived class provides.

the solution is to define the python drawContents function as:

   def drawContents(self,*args):
      if len(args)==1:
         return apply(qt.QFrame.drawContents,(self,)+args)

I imagine that things get more hairy still when there are two overloads that
have the same number of arguments but different types.


   :gurfle: /ger'fl/ interj.  An expression of shocked disbelief.
"He said we have to recode this thing in FORTRAN by next week.	Gurfle!"
Compare {weeble}.

  [ Toby Sargeant : Inpharmatica : Developer : t.sargeant at inpharmatica.co.uk ]
      [ http://www.inpharmatica.co.uk : 020 7074 4600 fax 020 7631 4844 ]

More information about the PyQt mailing list