I have a problem with Qt / C ++ with a simple QWidget program that draws an ellipse inside a child QWidget .
The program consists of:
(1) Parent of QWidget
(2) QWidget Child (used as a drawing surface for an ellipse)
(3) Draw QPushButton
Here is a piece of code (QPushButton Slot and Signal code are omitted for simplicity)
void Draw::paintEvent(QPaintEvent *event) { QPainter painter; painter.begin(child_Widget); //The line with the problem painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen(Qt::black, 12, Qt::DashDotLine, Qt::RoundCap)); painter.setBrush(QBrush(Qt::green, Qt::SolidPattern)); painter.drawEllipse(50, 50, 100, 100); painter.end();}
Line 2 painter.begin(child_Widget); doing nothing. The program draws an ellipse only if I replace line 2 with painter.begin(this); , but painted on the parent QWidget , and not on the child QWidget as desired.
PS I have a child_Widget hosted inside a GroupBox, which in turn is inside a QVBoxLayout .
Any suggestion?
Thanks.
source share