Results 1 to 3 of 3

Thread: Painting outside widget geometry?

  1. #1
    Join Date
    Jan 2006
    Location
    Minnesota
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Painting outside widget geometry?

    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 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Painting outside widget geometry?

    The painter is clipped to the widget rectangle, so that you can't paint over other widgets, you shouldn't try to override it. You could create external widgets for your arms and set their background to be invisible and move those widgets along with the "main" widget.

  3. #3
    Join Date
    Jan 2006
    Location
    Minnesota
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting outside widget geometry?

    Thanks. That's what I figured the problem was. I'll try to create the arms the way you said, and see how that works.

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Accelerate Widget Painting
    By jpujolf in forum Qt Programming
    Replies: 0
    Last Post: 23rd September 2008, 15:33
  3. Manually adjust geometry in custom widget
    By Rooster in forum Newbie
    Replies: 6
    Last Post: 30th June 2008, 02:44
  4. painting a widget outside a paintEvent
    By jayw710 in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2007, 23:18
  5. QRubberBand painting in the scroll area widget
    By SkripT in forum Qt Programming
    Replies: 7
    Last Post: 17th January 2006, 16:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.