Alex Rivera | Logout

Qt4 How to draw inside a widget?

Asked 2010-10-08T22:26:02.030
16

Qt4, QtCreator

I am trying to draw inside Widget:

void Widget::on_pushButton_clicked()
{
    QPainter painter;

    painter.begin(ui->label);

    QRectF rectangle(10.0, 20.0, 80.0, 60.0);
     int startAngle = 30 * 16;
     int spanAngle = 120 * 16;
     painter.drawArc(rectangle, startAngle, spanAngle);

    painter.end();
}

But when I press button nothing happens.

How to do this right way?

Edit
Report

1 Answer

1

If you overwrite the paint-method as described by Arnold Spence, you should call the parent's paintEvent or you end up with a widget that only shows your rectangle on a white background.

answered 2010-10-09T16:03:08.910

Your Answer