PDA

View Full Version : how can i clear qpainter drawings



athulms
23rd August 2011, 13:13
How can i clear all the drawings i have done with qpainter?

Rachol
23rd August 2011, 13:23
This is a little bit to little to know what you meant to ask :) I can just guess:


void QPainter::eraseRect ( const QRectF & rectangle )

athulms
25th August 2011, 08:48
void mainwindow::paintEvent(QPaintEvent *e)
{
painter=new QPainter(this);
QPen linepen(Qt::red);
linepen.setCapStyle(Qt::RoundCap);
linepen.setWidth(25);
painter->setRenderHint(QPainter::Antialiasing,true);
painter->setPen(linepen);
drawing(painter);
}
void mainwindow::drawing(QPainter *painter)
{
painter->drawLine(point,point2);
timer3 = new QTimer(this);
timer3->start(200);
connect(timer3, SIGNAL(timeout()), this, SLOT(erase(QPainter *)));
}
void mainwindow::erase(QPainter *painter)
{

painter->eraseRect(100,40,550,440);
timer3->stop();
}
{


I have to erase the line i have drawn after 200ms. But this code doesnot work what can i do?

wysota
25th August 2011, 08:55
I have to erase the line i have drawn after 200ms. But this code doesnot work what can i do?
Schedule an update after 200ms with a timer and don't draw the line in the paint event.

Rachol
25th August 2011, 09:18
In my opinion the code example you have given should be fixed in many ways:

1.You are creating new QPainter and QTimer objects every time you enter paintEvent method. That's a memory leak if you don't have it deleted.

2. You should not draw a widget outside a paintEvent, what you are actually doing in the erase method.

3. Is the connection you made actually working? It doesn't look correct to me.

After getting rid off these errors, you shoud then use Wysota's tip.