PDA

View Full Version : Draw Line



sagirahmed
18th October 2010, 05:39
Hi,

I want to draw line without writing code in paintEvent() function. I don't want to declare
or define the PaintEvent() function. I want to write my own function.

Thanks and Regards

tbscope
18th October 2010, 06:15
Let's see what the documentation says:


Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent widget attribute is set. On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting.

So, if you want to paint directly on the widget, you need to implement the paint event. You can call your own functions from within the paint event.

But, you can also paint on a pixmap or picture, then you don't need the paint event. But you need a widget that displays the picture (a QLabel for example).

Lykurg
18th October 2010, 07:31
On other option is also to install an event filter, catch the paint event and then draw there.

Ceelaz
18th October 2010, 07:46
What do you like to draw exactly? Do you like to draw a line on an existing widget?
Then you have to re-implement the paintEvent()-Method in a subclass of the widget. You can call Subclass::paintEvent(event); to draw the widget and then use QPainter to draw extra stuff on it...

It is possible to write your own paint()-Funktion but you have to call it from the paintEvent()-Method, otherwise it will not work out.

Lykurg
18th October 2010, 07:48
It is possible to write your own paint()-Funktion but you have to call it from the paintEvent()-Method, otherwise it will not work out.
That is as said not true! You can fetch a paint event and draw from outside the widget in any event filter without to touch paintEvent().

aamer4yu
18th October 2010, 07:49
Well... go ahead.. write your own function..
in your function.. draw the line onto a pixmap.. and then set this pixmap on a label..

but that wud be inefficient,, dont you think so ? :rolleyes: