Hello all!

I need to subclass QWidget, but its not working. When I call the function desenhaFluxo(), it returns the error:
QWidget:aintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
QPainter::setPen: Painter not active

How can I do that?

Qt Code:
  1. #include "fluxocaixawidget.h"
  2.  
  3. fluxoCaixaWidget::fluxoCaixaWidget(QWidget *parent) :
  4. QWidget(parent)
  5. {
  6.  
  7. }
  8.  
  9. void fluxoCaixaWidget::paintEvent(QPaintEvent *)
  10. {
  11. QPainter painter(this);
  12.  
  13. QPen caneta(Qt::black);
  14. caneta.setWidth(4);
  15. painter.setPen(caneta);
  16.  
  17.  
  18.  
  19. painter.drawLine(20, this->parentWidget()->height() / 2 - 20, this->parentWidget()->width()-40, this->parentWidget()->height() / 2 - 20);
  20. }
  21.  
  22. void fluxoCaixaWidget::desenhaFluxo()
  23. {
  24. QPainter painter(this);
  25.  
  26. QPen caneta(Qt::black);
  27. caneta.setWidth(4);
  28. painter.setPen(caneta);
  29.  
  30. painter.drawLine(10,10,50,10);
  31. }
To copy to clipboard, switch view to plain text mode