PDA

View Full Version : repainting through paintEvent() function



salmanmanekia
6th August 2008, 08:32
Hi
i am making an application in which i initially drew some ellipse and circle,
now the problem i am facing is that that then i got a signal from other class
at this signal i want to repaint inside the previously drawn ellipse so
in my paintEvent() function how could i define that that code should work only when signal is emmited or do i have to define another slot with a painter function to listen to that signal...

aamer4yu
6th August 2008, 08:44
Keep a variable in your class which will be used in the paintEvent what to draw and what to not :)
like

OnMySignal()
{
drawInsideEllipse = true;
}

paintEvent()
{
if(drawInsideEllipse)
// draw what u want ;
}


Hope u get the idea :)

salmanmanekia
6th August 2008, 08:47
thanks aamir...i already did the same thing ...initially i was lost in the details of my classes and signals ,so i just wasnt able to think ..anyways thanks again ;)

salmanmanekia
6th August 2008, 08:52
by the way i also tried the repaint() slot ,i know it is not useful in my case but i just got an error,the declaration is as follows in my
.h file

QRegion r1
.cpp

//in constructor
r1(x,y,w,h,QRegion::Ellipse);
//in a slot
repaint(r1) // error thrown here;

aamer4yu
6th August 2008, 09:20
Well, using repaint might not be a good idea...

From the docs -

void QWidget::repaint () [slot]
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden.
We suggest only using repaint() if you need an immediate repaint, for example during animation. In almost all circumstances update() is better, as it permits Qt to optimize for speed and minimize flicker.
Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may get infinite recursion. The update() function never causes recursion.
See also update(), paintEvent(), and setUpdatesEnabled().


Use update() instead. Modify ur code accordingly. I hope urs is not a animation requirement ;)

Nithya
6th August 2008, 12:50
SOlution to fix ur bug:
I guess u r trying to use the constructor

QRegion ( int x, int y, int w, int h, RegionType t = Rectangle )

For that in the constructor



1.
//in constructor
2.
r1=QRegion ((x,y,w,h,QRegion::Ellipse);
3.
//in a slot
4.
repaint((const QRegion)r1) // error thrown here;
5.


try out this