title: Paint device returned engine == 0, type: 1
body: <p>I have seen many answers for the same Question, I have already gone through them but none them solved my problem, I am getting the error </p>
  
  <blockquote>
    <p>QWidget::paintEngine: Should no longer be called
    QPainter::begin: Paint device returned engine == 0, type: 1
    QPainter::end: Painter not active, aborted</p>
  </blockquote>
  
  <p>I need to know,  What is type : 1, and why this error showing,</p>
  
  <p>My code is</p>
  
  <p>iconwidget.h </p>
  
  <pre><code>class IconWigdet : public QAbstractButton
  {
  Q_OBJECT
  QRect *iconarea;
  QPainter p;
  QPixmap *icon; 
  public:
  explicit IconWigdet(QRect *rectangle,QPixmap *tempicon);
  void paintEvent(QPaintEvent *);  
  };
  </code></pre>
  
  <p>iconwidget.cpp</p>
  
  <pre><code>IconWigdet::IconWigdet(QRect *rectangle,QPixmap *tempicon)
  {
  iconarea = new QRect();
  *iconarea = *rectangle  ;
  icon = new QPixmap(*tempicon);
  this-&gt;setGeometry(0,0,iconarea-&gt;width(),iconarea-&gt;height()+20);
  }
  
  void IconWigdet::paintEvent(QPaintEvent *)
  {
  qDebug() &lt;&lt; " PaintEvent ";
  p.begin(this);
  p.drawText(iconarea-&gt;x()+ 10,iconarea-&gt;height()+10, "name");
  p.drawPixmap ( *iconarea,*icon );
  p.end();
  }
  </code></pre>
  
  <p>groupwidget.h</p>
  
  <pre><code>class GroupWidget: public QWidget
  {
  Q_OBJECT
  QGridLayout *groupLayout = new QGridLayout ;
  QRect *rect = new QRect( 0, 0, 100, 100);
  QPixmap *pimap = new QPixmap("../widgeticon/icons/ball.png");
  IconWigdet *icon = new IconWigdet(rect,pimap);
  public:
  GroupWidget();
  };
  </code></pre>
  
  <p>groupwidget.cpp</p>
  
  <pre><code>GroupWidget::GroupWidget()
  { 
  groupLayout-&gt;addWidget(icon, 0, 1, 1, 1, 0);
  this-&gt;setLayout(groupLayout);
  icon-&gt;show();
  QPaintEvent *e;
  icon-&gt;paintEvent(e);
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  QApplication a(argc, argv);
  GroupWidget *Gw = new GroupWidget;
  Gw-&gt;show();
  return a.exec();
  }
  </code></pre>
  
  <p>and the iconwidget class will work perfectly if the main function changed to</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  QApplication a(argc, argv);;   
  QRect *rect = new QRect( 0, 0, 100, 100);
  QPixmap *pimap = new QPixmap("../widgeticon/icons/ball.png");
  IconWigdet *Iw = new IconWigdet(rect,pimap);
  Iw-&gt;show();
  return a.exec();
  }
  </code></pre>
  
  <p>that means, If we use iconwidget class object in main function it is working, but it is not working  when we do the same in groupwidget class,</p>
  
  <p>Thanks in advance</p>