title: Qt5 paintEvent() region too small
body: <p>I wanted to implement a custom widget. When adding a <code>Node</code> object to the owning <code>Graph</code> widget by a double click, the <code>Node::paintEvent</code> happens rightfully, but the region of the <code>QPaintEvent</code> is constant and too small regardless of where I added it. The indicated bounding repaint box is always at (0,0) with width/height of (100,30).</p>
  
  <p>Any Ideas why this is the case?</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QMainWindow&gt;
  #include &lt;QPainter&gt;
  #include &lt;QMouseEvent&gt;
  
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  #define DEBUG(lvl, x) \
      std::clog &lt;&lt; "L" &lt;&lt; __LINE__ &lt;&lt; ": " &lt;&lt; x &lt;&lt; "\n";
  
  class Node final : public QWidget
  {
  protected:
      void paintEvent (QPaintEvent * event) override {
          DEBUG(0, "Node::paintEvent");
          QPainter painter(this);
          painter.setBrush(QColor(127,127,127));
          painter.drawRect(posX, posY, width, height);
          auto x = event-&gt;rect();
          DEBUG(0, "PaintBox:" &lt;&lt; x.x() &lt;&lt; "::" &lt;&lt; x.y() &lt;&lt; "::" &lt;&lt; x.width() &lt;&lt; "::" &lt;&lt; x.height());
      }
  public:
      explicit Node (QWidget * parent = 0): QWidget(parent) {}
      int posX{0}, posY{0}, width{60}, height{60};
  };
  
  class GraphView final : public QWidget
  {
  public:
      explicit GraphView (QWidget * parent = 0): QWidget(parent) {}
  protected:
      void paintEvent (QPaintEvent *) override {
          DEBUG(0, "GraphView::paintEvent");
      }
  
      void mouseDoubleClickEvent (QMouseEvent * event) override {
          DEBUG(0, "mouseDoubleClickEvent");
          auto ptr = new Node(this);
          ptr-&gt;posX = event-&gt;x();
          ptr-&gt;posY = event-&gt;y();
          nodes.push_back(ptr);
          ptr-&gt;show();
      }
  
      void mousePressEvent (QMouseEvent * event) override {
          DEBUG(0, "mousePressEvent");
          auto ptr = static_cast&lt;Node*&gt;(childAt(event-&gt;pos()));
          if (ptr) {
              DEBUG(0, "FOUND X");
          }
      }
      std::vector&lt;Node*&gt; nodes;
  };
  
  
  int main (int argc, char *argv[])
  {
      QApplication a(argc, argv);
  
      auto* gv = new GraphView{};
      QMainWindow w;
      w.setCentralWidget(gv);
      w.resize(640, 480);
      w.show();
  
      return a.exec();
  }
  </code></pre>
  
  <p>On a double click anywhere on the window area this is returned:</p>
  
  <pre><code>L34: GraphView::paintEvent
  L48: mousePressEvent
  L38: mouseDoubleClickEvent
  L34: GraphView::paintEvent
  L16: Node::paintEvent
  L21: PaintBox:0::0::100::30
  </code></pre>
  
  <p>If you double click on an area between 0,0 and 100,30 the Node is displayed like it should.</p>