title: Qt: QWidget::paintEngine: Should no longer be called
body: <p>I'm trying to make an app where you can draw with your finger on a canvas.<br>
  To achieve this, I'm subclassing <code>QWidget</code> as <code>MFCanvas</code>, registered the class in QML with<br>
  <code>qmlRegisterType&lt;&gt;()</code>, implementing the virtual <code>paintEvent();</code> function, and <br>
  drawing on it with a <code>QPainter</code> inside the <code>paintEvent();</code> function.<br>
  <br>
  The Problem:<br>
  Upon construction, the <code>QPainter</code> throws this warning:<br></p>
  
  <blockquote>
    <p>QWidget::paintEngine: Should no longer be called</p>
  </blockquote>
  
  <p>Then, serveral other related warnings are thrown:<br></p>
  
  <pre><code>QPainter::begin: Paint device returned engine == 0, type: 1
  QPainter::setPen: Painter not active
  </code></pre>
  
  <p>No wonder: the <code>QPainter</code> didn't draw anything...<br>
  Also, am i supposed to call <code>paintEvent();</code> by myself?<br>
  Or should it be called every frame by <code>QWidget</code>, and i somehow messed it up?<br>
  <br>
  I searched the web, but all posts i found had either no answer to them, or they where <br>
  using something else than <code>QWidget</code>.<br>
  <br>
  My Code:<br>
  <br>
  mfcanvas.cpp:</p>
  
  <pre><code>#include "mfcanvas.h"
  #include &lt;QDebug&gt;
  #include &lt;QPainter&gt;
  #include &lt;QVector2D&gt;
  #include &lt;QList&gt;
  
  MFCanvas::MFCanvas(QWidget *parent) : QWidget(parent)
  {
      paths = new QList&lt;QList&lt;QVector2D&gt;*&gt;();
      current = NULL;
      QWidget::resize(100, 100);
  }
  
  MFCanvas::~MFCanvas()
  {
      delete paths;
  }
  
  void MFCanvas::paintEvent(QPaintEvent *)
  {
      if(current!=NULL){
          if(current-&gt;length() &gt; 1){
              QPainter painter(this);
              painter.setPen(Qt::black);
              for(int i = 1; i &lt; current-&gt;length(); i++){
                  painter.drawLine(current-&gt;at(i-1).x(), current-&gt;at(i-1).y(), current-&gt;at(i).x(), current-&gt;at(i).y());
              }
          }
      }
  }
  
  void MFCanvas::pressed(float x, float y)
  {
      if(current==NULL){
          qDebug() &lt;&lt; "null:"&lt;&lt;current;
          current = new QList&lt;QVector2D&gt;();
          current-&gt;append(QVector2D(x, y));
      }else{
          qDebug() &lt;&lt; "current:"&lt;&lt;current;
      }
      paintEvent(NULL);
  }
  
  void MFCanvas::update(float x, float y)
  {
      current-&gt;append(QVector2D(x, y));
  }
  
  void MFCanvas::resize(int w, int h)
  {
      QWidget::resize(w, h);
  }
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QQmlApplicationEngine&gt;
  #include &lt;QtQml&gt;
  #include &lt;QSurfaceFormat&gt;
  #include "creator.h"
  #include "mfcanvas.h"
  
  int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
  
      qmlRegisterType&lt;MFCanvas&gt;("com.cpp.mfcanvas", 1, 0, "MFCanvas");
  
      QQmlApplicationEngine engine;
  
      QQmlComponent *component = new QQmlComponent(&amp;engine);
      QObject::connect(&amp;engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
  
      Creator creator(component);
      QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)), &amp;creator, SLOT(create(QQmlComponent::Status)));
  
      component-&gt;loadUrl(QUrl("qrc:///main.qml"));
  
      int rv;
  
      rv = app.exec();
      delete component;
      return rv;
  }
  </code></pre>
  
  <p>creator.cpp:</p>
  
  <pre><code>#include "creator.h"
  #include &lt;QQuickWindow&gt;
  #include &lt;QDebug&gt;
  
  Creator::Creator(QQmlComponent *component)
  {
      this-&gt;component = component;
  }
  
  void Creator::create(QQmlComponent::Status status)
  {
      if(status == QQmlComponent::Ready){
          QObject *topLevel = component-&gt;create();
          QQuickWindow::setDefaultAlphaBuffer(true);
          QQuickWindow *window = qobject_cast&lt;QQuickWindow *&gt;(topLevel);
  
          QSurfaceFormat surfaceFormat = window-&gt;requestedFormat();
          window-&gt;setFormat(surfaceFormat);
          window-&gt;show();
      }
  }
  </code></pre>
  
  <p>main.qml: (the important part)</p>
  
  <pre><code>import QtQuick 2.2
  import QtQuick.Controls 1.1
  import QtQuick.Controls.Styles 1.2
  import QtQuick.Layouts 1.1
  import QtQuick.Window 2.0
  import com.cpp.mfcanvas 1.0
  
  ApplicationWindow {
      visible: true
      width: 640
      height: 480
      title: qsTr("MFCanvas")
  
      onSceneGraphInitialized: {
          drawMenu.visible = true;
          lineWidth.visible = true;
          colorMenu.visible = true;
          drawMenu.visible = false;
          lineWidth.visible = false;
          colorMenu.visible = false;
      }
  
      Rectangle {
          id: main
          anchors.fill: parent
  
          property real toolsH: 15
          property real iconW: 25
  
          property real menuH: 8
          property real menuW: 16
  
          property real dpi: (Screen.logicalPixelDensity == undefined ? 6 : Screen.logicalPixelDensity) * 1.5
  
          property color choosenColor: Qt.hsla(hue.value, saturation.value, luminance.value, 1)
  
          Text {
              anchors.centerIn: parent
              font.pointSize: 60
              text: "MFCanvas"
          }
  
          MFCanvas {
              id: canvas
              Component.onCompleted: {
                  canvas.resize(main.width, main.height);
              }
          }
      //...
      }
  }
  </code></pre>
  
  <p>Tell me if you need any additional information.<br>
  Thank you in advance! =)<br></p>