repainting through paintEvent() function
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...
Re: repainting through paintEvent() function
Keep a variable in your class which will be used in the paintEvent what to draw and what to not :)
like
Code:
OnMySignal()
{
drawInsideEllipse = true;
}
paintEvent()
{
if(drawInsideEllipse)
// draw what u want ;
}
Hope u get the idea :)
Re: repainting through paintEvent() function
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 ;)
Re: repainting through paintEvent() function
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
.cpp
Code:
//in constructor
//in a slot
repaint(r1) // error thrown here;
Re: repainting through paintEvent() function
Well, using repaint might not be a good idea...
From the docs -
Quote:
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 ;)
Re: repainting through paintEvent() function
SOlution to fix ur bug:
I guess u r trying to use the constructor
Code:
QRegion ( int x,
int y,
int w,
int h, RegionType t
= Rectangle
)
For that in the constructor
Code:
1.
//in constructor
2.
3.
//in a slot
4.
repaint((const QRegion)r1
) // error thrown here; 5.
try out this