title: QPainter error in GUI application
body: <p>I'm trying to write a GUI that paints a graph onto it in C++. I am getting a list of errors, all of which say:
  "QPainter::begin: Widget painting can onnly begin as a result of a paintEvent"
  Nothing appears to be painting.</p>
  
  <h2>main.cpp</h2>
  
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QFont&gt;
  #include &lt;QPushButton&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  #include "skewNormal.h"
  #include "ui.h"
  
  int main(int argc, char* argv[])
  {
      QApplication app(argc, argv);
      Window w;
      #if defined(Q_OS_SYMBIAN)
      w.showMaximized();
      #else
      w.show();
      #endif
      return app.exec();
  }
  </code></pre>
  
  <h2>ui.h</h2>
  
  <pre><code>#ifndef UI_H_INCLUDED
  #define UI_H_INCLUDED
  #include &lt;QtGui/QMainWindow&gt;
  
  class Window : public QWidget
  {
      public:
      Window();
  
      void paintEvent ( QPaintEvent * event );
  };
  
  
  
  #endif // UI_H_INCLUDED
  </code></pre>
  
  <h2>ui.cpp</h2>
  
  <pre><code>#ifndef GRAPHPN3670_H
  #define GRAPHPN3670_H
  
  #include &lt;QtCore/QVariant&gt;
  #include &lt;QtGui/QAction&gt;
  #include &lt;QtGui/QApplication&gt;
  #include &lt;QtGui/QPaintEvent&gt;
  #include &lt;QtGui/QGraphicsView&gt;
  #include &lt;QtGui/QHeaderView&gt;
  #include &lt;QtGui/QMainWindow&gt;
  #include &lt;QtGui/QMenuBar&gt;
  #include &lt;QtGui/QStatusBar&gt;
  #include &lt;QtGui/QWidget&gt;
  #include &lt;QtCore/QRect&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  #include "ui.h"
  #include "skewNormal.h"
  
  Window::Window()
  {
      cout&lt;&lt;"Hello1";
  }
  
  void Window::paintEvent ( QPaintEvent * event ){
      cout&lt;&lt;"Hello from paint event";
      QPainter p(this);
      int xL = -width() / 2;
      int yL = 0;
      for(int x = -width() / 2; x &lt; width() / 2; x++)
      {
          int y = getSkewNormal(0.5, x);
          p.drawLine(xL + width() / 2, height() - yL, x + width() / 2, height() - y);
          xL = x;
          yL = y;
      }
  }
  
  #endif // GRAPHPE3488_H
  </code></pre>