Overloading virtual method of widget without inheriting (PyQt)

Alex Gusarov alex.m.gusarov at gmail.com
Tue May 27 03:31:35 EDT 2008


Hello, I have strong .NET background with C# and want to do some
familiar things from it with Python, but don't know how. For example,
I created form in qt designer with QCalendarWidget, translated it into
Python module and want to overload virtual method paintCell of
QCalendarWidget. In C# I can write following (abstract) code:

this.calendar.PaintCell += new PaintEventHandler(myPaintCellHandler);

void myPaintCellHandler(object sender, PaintEventArgs e) {
    // some work here
}

I can't find how I can do similar thing in Python without inheriting
QCalendarWidget and overloading this method in inherited class (it's
long and I must create additional class). The only thing I done its
full replacement of handler:

calendar.paintCell = myPaintCell

def myPaintCell(self):
    pass

Operator += don't work with methods. So, I can't add handler or call
standart handler from my (infinite recursion, cause my handler
replaced standart)

Please, give me some advice, I know Python must be good enough to do
such things fast and elegant.

--
Best regards, Alex Gusarov



More information about the Python-list mailing list