I have a QWidget that I am overriding the paintEvent method. The widget is basically a square with some "arms" . For the most part I want to be able to move this widget around using widget->move(x,y); But I added a new method to extend the "arms" of the widget. My problem is that the widget's size is the size of the rectangle I want to draw. And when I try to draw the "arms" they do not get drawn.

Here is my code in the paint event.

Qt Code:
  1. void MyWidget::paintEvent(QPaintEvent * event)
  2. {
  3. double dWidth = width();
  4. double dHeight = height();
  5.  
  6. QPainter painter(this);
  7. painter.setRenderHint(QPainter::Antialiasing);
  8.  
  9.  
  10. painter.save();
  11. QPen pen(Qt::black);
  12. pen.setWidth(5);
  13. painter.setPen(pen);
  14.  
  15. QRectF rect(0.0,0.0,dWidth,dHeight);
  16. painter.drawRect(rect);
  17.  
  18. pen.setColor(Qt::red);
  19. painter.setPen(pen);
  20.  
  21. if ( m_nArmY < 0 )
  22. {
  23. QLineF arm1(0.0,0.0,0.0,m_nArmY);
  24. QLineF arm2(dWidth,0.0,dWidth,m_nArmY);
  25.  
  26. painter.drawLine(arm1);
  27. painter.drawLine(arm2);
  28. }
  29. else
  30. {
  31. QLineF arm1(0.0,dHeight,0.0,m_nArmY + dHeight);
  32. QLineF arm2(dWidth,dHeight,dWidth,m_nArmY + dHeight);
  33.  
  34. painter.drawLine(arm1);
  35. painter.drawLine(arm2);
  36. }
  37.  
  38.  
  39. painter.restore();
  40. }
To copy to clipboard, switch view to plain text mode