PDA

View Full Version : Error while redrawing using QPainter Class



sosanjay
16th December 2009, 08:57
Hi All,

I am using QPainter class to draw line on the button event.
I am using three push button on which every button different layouts of the line will draw.

First time it works well but when I press rapidly few times then overwriting will occur.
I am using painter.eraseRect(0,0,281,191); but it not works

Can anyone help me to clear the label everytime when I draw.
In Qt there is no painter.clear() properties.

How can I clear the screen every time before I draw.




In 1st Push button I write

QPixmap pix(281,191);
QPen Pen((QColor::QColor (255,255,255,255)),2);

QLineF line1(0,50,281,50);
painter.eraseRect(0,0,281,191);
painter.begin(&pix);
painter.setPen(Pen);
painter.drawLine(line1);
painter.end();

In 2nd button I write

QPixmap pix(281,191);
QPen Pen((QColor::QColor (255,255,255,255)),2);
QLineF line1(60,50,281,50);
QLineF line2(60,141,281,141);
QLineF line3(60,0,60,191);
painter.eraseRect(0,0,281,191);
painter.begin(&pix);
painter.setPen(Pen);
painter.drawLine(line1);
painter.drawLine(line2);
painter.drawLine(line3);
painter.end();

so on..

wysota
16th December 2009, 09:19
You don't have to clear the label. Qt will auto-erase its contents before every paint event.

sosanjay
16th December 2009, 11:06
I am sending you the image Please check it.

Initially it display correct but after clicking few times some default color comes.

How can I solve this?

Thanks for Reply.

wysota
16th December 2009, 12:05
Please provide a minimal compilable example reproducing the problem.

sosanjay
28th December 2009, 07:41
Hi wysota,

I am sending you the sample code of drawline. Please check it I am trying lot to solve but I did not get the error.

I am using clear(); clearMask(); for clearing the label but unwanted lines comes.

In sample code there is four push button and according to button line will be drawn.
Initially it display according to the code but when I press rapidly 40-50 times then unwanted line comes.

Thanks in advance.

wysota
28th December 2009, 12:48
Fill the pixmap with transparency (or whatever other colour you want) before you start drawing on it.


QPixmap pix(...,...);
pix.fill(Qt::transparent);