473,289 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Re: Overloading virtual method of widget without inheriting (PyQt)

On Mon May 26 17:37:04 CEST 2008, 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
}
Right. I vaguely remember someone showing something like this at EuroPython
a couple of years ago. I believe that this approach is actually registering
an event handler (or callback) to handle a certain type of event.
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).
Just out of interest, given that you have to put the event handler somewhere,
why is it a problem to derive a new class and reimplement paintCell()?

It really isn't that much code:

class MyCalendarWidget(QCalendarWidget):

def paintCell(self, painter, rect, date):
# some work here
So, I need to run my code whenever paintCell is called by Qt internals and
I have no enough experience with Python for it. Please, give me some
advice, I know Python must be good enough to do such things.
The principal mechanism for doing this is via inheritance. You can do things
with event filters, but it's more complex and almost like working against the
design of the library to do so.

I have a feeling that the form produced by Qt Designer, once converted to
code, contains references to QCalendarWidget where you really want to use a
customized calendar widget. If so, you should "promote" the calendar widget
in Qt Designer to use your widget instead, and make sure you import the
module that supplies it in your application.

If you need more information about this, just ask.

David
--
David Boddie
Lead Technical Writer, Trolltech ASA
Jun 27 '08 #1
0 1051

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Terje Slettebø | last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been discussed before, I'd appreciate a pointer to it. I again haven't found it in a search of the PHP groups. The PHP...
2
by: Srinath Avadhanula | last post by:
Hello, Sorry to be bringing up what seems to be a somewhat beaten up topic... This is what I wanted to do: Create a _simple_ text editor widget which supports VI(M) style keybindings but...
10
by: Peter | last post by:
I want to draw some lines on a widget. This works ok, but when I want to redraw, the old lines are still there. How do I clear or refresh the widget, so I can draw a new set of lines? Code...
5
by: Torsten Curdt | last post by:
Let's assume I have a base class class X { }; and the the following classes inheriting class BX : public X {
3
by: Steven T. Hatton | last post by:
I stumbled upon this blog while googling for something. I have to say, I really don't understand what Lippman is trying to tell me here. I included the first paragraph for context, but the second...
31
by: | last post by:
Hi, Why can I not overload on just the return type? Say for example. public int blah(int x) { }
5
by: toton | last post by:
Hi, I want a few of my class to overload from a base class, where the base class contains common functionality. This is to avoid repetition of code, and may be reducing amount of code in binary,...
2
by: skawaii | last post by:
Ok, here's what's going on. I've just created a custom widget. it works great. I'm having some trouble, however, figuring out how to allow the said widget to resize. For example, when I throw the...
7
by: Alex Gusarov | last post by:
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.