how to draw points with qpainter?
Code:
{
point=f->pos();
y=1;
update();
}
{
linepen.setCapStyle(Qt::RoundCap);
linepen.setWidth(30);
painter.
setRenderHint(QPainter::Antialiasing,
true);
painter.setPen(linepen);
if(y==1)
painter.drawPoint(point);
}
i have used the code. but draws only single point. when i click to draw a second point the first point will disappear. at a time only one point will appear..
Re: how to draw points with qpainter?
Its because paintEvent clears the widget before painting, so everything previously painted is gone.
You should try using a QList of points to store every clicked point and paint all of them.
Re: how to draw points with qpainter?
k i will try to do it. thanks
Added after 29 minutes:
Code:
{
point=e->pos();
update();
}
{
setAttribute(Qt::WA_OpaquePaintEvent);
linepen.setCapStyle(Qt::RoundCap);
linepen.setWidth(30);
painter.
setRenderHint(QPainter::Antialiasing,
true);
painter.setPen(linepen);
painter.drawPoint(point);
}
it worked for no need for list
Re: how to draw points with qpainter?
Quote:
it worked for no need for list
That is only because you are only using your dedicated painting in your paint event.
But what if you want the standard painting AND your painting?
Or if you cover your widget with another window, and then show your widget again?
Then you will only get the last point.
What stampede suggested is the correct way.
Re: how to draw points with qpainter?
k thanks i will do it with list