Overloading virtual method of widget without inheriting (PyQt)
Francesco Bochicchio
bockman at virgilio.it
Tue May 27 13:46:08 EDT 2008
On Tue, 27 May 2008 01:31:35 -0700, Alex Gusarov wrote:
> 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
>
It is more a matter of the GUI toolkit you are using rather than the
language. In Python, they are many, but they are not as tighty integrated
with the language as in C#. Also, Python has a no standard support for
event handling, but again several non-standard library (e.g. twisted ) and
plus you can relatively easily cook your own recipe, has other posters
have shown you.
Anyway, IIRC (it's a long time since I used Qt), QT allows to connect
more than one slot with the same signal, so you should not need to
subclass or to create your own multi-dispatcher. Just doing:
calendar.paintCell.signal( SOME_SIGNAL_NAME, my_paint_method )
should work. I don't know which signal you should connect to, however.
This link gives you some detail on signal/slots in PyQT:
http://www.commandprompt.com/community/pyqt/x1408
Ciao
-----
FB
More information about the Python-list
mailing list