title: QPainter::begin: Widget painting can only begin as a result of a paintEvent
body: <p>The code works but I get the following warning message while I press the mouse while it is executing:  ??</p>
  
  <pre><code>QPainter::begin: Widget painting can only begin as a result of a paintEvent
  QPainter::setPen: Painter not active
  QPainter::drawRects: Painter not active
  </code></pre>
  
  <p>added modification further down</p>
  
  <hr>
  
  <pre><code>#include &lt;QTextEdit&gt;
  
  class QTextEditEnter : public QTextEdit
  {
      Q_OBJECT
  public:
      QTextEditEnter(QWidget *_parent);
  
  protected:
      virtual void paintEvent(QPaintEvent *_event);
      void mousePressEvent(QMouseEvent *evt);
      int m_color;
      void mouseDoubleClickEvent(QMouseEvent *e);
  signals:
      void signalPressEnter();
  };
  </code></pre>
  
  <hr>
  
  <pre><code>#include "qtexteditenter.h"
  #include &lt;qpainter.h&gt;
  #include &lt;QMouseEvent&gt;
  
  QTextEditEnter::QTextEditEnter(QWidget *_parent) :
      QTextEdit(_parent)
  {
      this-&gt;setFrameStyle(QFrame::Sunken);
      m_color = 0;
      setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
  }
  
  
  void QTextEditEnter::paintEvent(QPaintEvent *_event)
  {
      QPainter pnt( viewport() );
      pnt.setPen( QColor( 255, 0, 0, 0xff ));
      pnt.drawRect( 0, 0, width()-1, height()-1);
  }
  
  
  void QTextEditEnter::mousePressEvent(QMouseEvent *e)
  {
      QPainter p(this-&gt;viewport());
      p.setPen(QColor(0,0,0,0xff));
      p.drawRect(this-&gt;viewport()-&gt;rect());
      p.begin(this);
  
      switch(m_color){
          case 0:
              p.setPen(Qt::red);
              break;
          case 1:
              p.setPen(Qt::green);
              break;
      }
      p.drawEllipse(e-&gt;pos(),2,2);
      p.end();
  }
  
  void QTextEditEnter::mouseDoubleClickEvent(QMouseEvent *e)
  {
      m_color++;
      if (m_color &gt; 1) m_color = 0;
  
  }
  </code></pre>
  
  <p>------------------- Modified ----------------</p>
  
  <pre><code>void QTextEditEnter::paintEvent(QPaintEvent *_event)
  {
  
      if(1){
          QPainter pnt( this-&gt;viewport());
  
          pnt.setPen( QColor( 0xff, 0, 0, 0xff ));
          pnt.drawRect( 0, 0, width()-1, height()-1);
  
          pnt.setPen( QColor( 0, 0xff, 0, 0xff ));
          pnt.drawRect( 10, 10, width()-20, height()-20);
      }
  
      if(flagModify == 1){
          QPainter p(this-&gt;viewport());
  
          switch(m_color){
              case 0:
                  p.setPen(Qt::red);
                  break;
              case 1:
                  p.setPen(Qt::green);
                  break;
          }
  
          p.begin(this);
          p.drawEllipse(x, y, 2, 2);
          p.end();
  
          flagModify = 0;
      }
  }
  
  
  void QTextEditEnter::mousePressEvent(QMouseEvent *e)
  {
      x = e-&gt;pos().x();
      y = e-&gt;pos().y();
  
      flagModify = 1;
      this-&gt;update(this-&gt;rect());
  }
  </code></pre>