PDA

View Full Version : how to draw outside paintevent?



athulms
19th August 2011, 10:23
void MainWindow::mousePressEvent(QMouseEvent *e)
{
point=e->pos();
setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
QPainter painter(ui->frame);
QPen linepen(Qt::red);
linepen.setCapStyle(Qt::RoundCap);
linepen.setWidth(30);
painter.setRenderHint(QPainter::Antialiasing,true) ;
painter.setPen(linepen);
painter.drawPoint(point);
}


I used this code but it doesnt work

high_flyer
19th August 2011, 10:30
You normally should not need this, and you normally should not do this.
There is a way, but probably you don't need it.
Maybe if you explain why and what you are trying to do, we can show you how to do it the proper way.
Why don't you just put that drawing code in to the paintEvent()?
You can simply set a flag in the mousePressEvent() and evaluate that flag in your painEvent() and paint it only if the flag is set, for example.

athulms
19th August 2011, 10:33
i got the code
void MainWindow::mousePressEvent(QMouseEvent *e)
{
point=e->pos();
update();
}
void MainWindow::paintEvent(QPaintEvent *e)
{
setAttribute(Qt::WA_OpaquePaintEvent);
QPainter painter(this);
QPen linepen(Qt::red);
linepen.setCapStyle(Qt::RoundCap);
linepen.setWidth(30);
painter.setRenderHint(QPainter::Antialiasing,true) ;
painter.setPen(linepen);
painter.drawPoint(point);
}


it worked for me

wysota
19th August 2011, 17:16
You shouldn't use OpaquePaintEvent in this situation. And certainly you shouldn't set the flag in the paint event.