title: Qt: Using QPainter on child widgets
body: <p>I'm having a Qt/C++ problem with a simple <code>QWidget</code> program that draws an ellipse inside a child <code>QWidget</code>.</p>
  
  <p><strong>The program is composed of:<br></strong>
  (1) A parent <code>QWidget</code> <br>
  (2) A child <code>QWidget</code> (used as the drawing surface for an ellipse)<br>
  (3) A draw <code>QPushButton</code><br></p>
  
  <p><strong>Here is part of the code (QPushButton Slot and Signal code omitted for simplicity)</strong></p>
  
  <pre><code>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();}
  </code></pre>
  
  <p>Line 2 <code>painter.begin(child_Widget);</code> doesn't do anything. The program draws the ellipse only if I replace line 2 with <code>painter.begin(this);</code> but that draws on the parent <code>QWidget</code> and not on the child <code>QWidget</code> as desired.</p>
  
  <p>P.S. I have the child_Widget housed inside a GroupBox which in turn is housed inside a <code>QVBoxLayout</code>.</p>
  
  <p>Any Suggestion?</p>
  
  <p>Thanks.</p>