[Qt-interest] What is wrong on QPainter?
Andre Haupt
andre at bitwigglers.org
Wed May 13 08:42:52 CEST 2009
On Wed, May 13, 2009 at 02:05:52PM +0200, Oliver.Knoll at comit.ch wrote:
> Stefanos Antaris wrote on Wednesday, May 13, 2009 1:59 PM:
>
> > ...
> > [code] painter =
> > new QPainter(this);
>
> What is "this"? A QWidget? QGLWidget? QPrinter?
>
> > ...
> > QPainterPath path;
> > path.moveTo(80,320);
> > path.cubicTo(200,80,320,80,480,320);
> >
> > painter->setPen(QPen(Qt::black,8));
> > painter->drawPath(path);
> >
> > [/code]
>
> When exactly is this code called?
>
> Given the fact that you do *not* deallocate your painter anywhere in your example code this gives me the impression that you try to execute this code in some c'tor instead! (which would not work!)
That is what he did as he mentioned in his post ;-)
@Stefanos:
You have to override paintEvent(). Put something like this in there
void MyWidget::paintEvent(QpaintEvent *e)
{
QPainter painter(this);
QPainterPath path;
path.moveTo(80,320);
path.cubicTo(200,80,320,80,480,320);
painter.setPen(QPen(Qt::black,8));
painter.drawPath(path);
}
regards,
Andre
More information about the Qt-interest-old
mailing list