QPainter painter(this); // 'this' is a widget painter.setBrush(Qt::blue); painter.drawEllipse(50, 50, 50, 50);
QPainter painter(this); // 'this' is a widget painter.setPen(Qt::red); painter.drawLine(0, 0, 100, 100);
QPainter painter(this); // 'this' is a widget QRectF rect(0, 0, 100, 100); painter.setBrush(Qt::green); painter.drawRoundedRect(rect, 10, 10);In this example, we create a QPainter object with the widget as the device. Then, we create a QRectF object with position (0, 0) and width and height of 100 pixels each. We set the brush color to green and draw a rounded rectangle with corner radius of 10 pixels. Package library: Qt library