Results 1 to 4 of 4

Thread: Repaint child without having the parent automatically repainted

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Repaint child without having the parent automatically repainted

    So you'd like your QGraphicsView contents to shine through into your widget, and you also want your widget to be able to redraw itself without redrawing the QGV. So if the QGV changes under your widget, then I assume you want the widget to recompose itself on top of the QGV, right?

    Have you tried QGraphicsView::render()? Try this. Enable the OpaquePaintEvent flag on your widget. Then call QGraphicsView::render() and then draw your widget contents. Like this (untested code):

    Qt Code:
    1. void OverlayWidget::paintEvent(QPaintEvent *event)
    2. {
    3. QPainter painter(this);
    4. graphicsView->render(rect(), &painter, geometry());
    5. ... do your painting here
    6. }
    To copy to clipboard, switch view to plain text mode 

    The render function will draw what's under your widget into your widget. So you're doing your own composition. You can also save your widget's background into a QPixmap to avoid asking QGraphicsView to render it all the time. The QGraphicsView, on its side, can do something like this:

    Qt Code:
    1. void CustomGraphicsView::paintEvent(QPaintEvent *event)
    2. {
    3. QRegion exposed = event->region();
    4. if (exposed.intersects(overlayWidget.geometry())) {
    5. QPixmap pixmap(overlayWidget.size());
    6. pixmap.fill(0);
    7. QPainter pixmapPainter(&pixmap);
    8. render(overlayWidget.rect(), &pixmapPainter, overlayWidget.geometry());
    9. overlayWidget->updateBackground(pixmap);
    10. }
    11. QGraphicsView::paintEvent(event);
    12. }
    To copy to clipboard, switch view to plain text mode 

    The idea being that the view updates the overlaywidget's background, so that the overlay can rerender it without asking the view all the time, and the view basically "pushes" changes to the overlay only when necessary....
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  2. The following user says thank you to Bitto for this useful post:

    durbrak (17th January 2008)

Similar Threads

  1. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:00
  2. Referencing Parent Widget from Child
    By taylor34 in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2006, 15:13

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
  •  
Qt is a trademark of The Qt Company.