Results 1 to 20 of 24

Thread: How to sendEvent QPaintEvent ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Question How to sendEvent QPaintEvent ?

    I want redraw one widget without hi's childs, how to use QProcess::sendEvent with QPaintEvent ? I try this, but this doesn't work:

    Qt Code:
    1. QPaintEvent *pe = new QPaintEvent(ui->groupBox->rect());
    2. ui->groupBox->setAttribute(Qt::WA_WState_InPaintEvent, true);
    3. QApplication::sendEvent(ui->groupBox, pe);
    4. ui->groupBox->setAttribute(Qt::WA_WState_InPaintEvent, false);
    To copy to clipboard, switch view to plain text mode 

    But this code work and i dont' undrestand why:

    Qt Code:
    1. QPaintEvent *pe = new QPaintEvent(ui->groupBox->rect());
    2. QPixmap pix(ui->groupBox->size());
    3. pix.fill(Qt::white);
    4. QPainter::setRedirected(ui->groupBox, &pix);
    5. QApplication::sendEvent(centralWidget(), pe);
    6. QPainter::restoreRedirected(ui->groupBox);
    7. pix.save("file.jpg");
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: How to sendEvent QPaintEvent ?

    What's wrong with calling repaint() or update? The children should be taken from the backing store if they didn't change and their background didn't change.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: How to sendEvent QPaintEvent ?

    Quote Originally Posted by wysota View Post
    What's wrong with calling repaint() or update? The children should be taken from the backing store if they didn't change and their background didn't change.
    I want prevent childrens repaint for overpainting from parent widget. I want change order for repaint recursion. Parent must be last.

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

    Default Re: How to sendEvent QPaintEvent ?

    But this will make it paint over the children so you would see nothing. If you really want that have an overlay widget that is transparent and uses QWidget::render() to retrieve a pixmap of the parent and use drawPixmap to paint it on itself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: How to sendEvent QPaintEvent ?

    We found other solution.


    installEventFilter for all childs, QApplication::sendEvent in QEvent::Paint for each child.

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to sendEvent QPaintEvent ?

    From the above pic, how do u expect to work with the combo box ?
    Also the hip hop screen looks more like a splash screen

  7. #7
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: How to sendEvent QPaintEvent ?

    Quote Originally Posted by aamer4yu View Post
    From the above pic, how do u expect to work with the combo box ?
    Also the hip hop screen looks more like a splash screen
    Combobox and etc will be over picture, this is true. But i thing this not really matter

    Also the hip hop screen looks more like a splash screen
    Only "looks like", this overpaint for each child.

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

    Default Re: How to sendEvent QPaintEvent ?

    Using an overlay this would have been much simpler and quicker in terms of performance

    [wiki]Widget Overlay[/wiki]
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: How to sendEvent QPaintEvent ?

    Quote Originally Posted by wysota View Post
    Using an overlay this would have been much simpler and quicker in terms of performance

    [wiki]Widget Overlay[/wiki]
    I read this page before, but for academic interest i want use only paint features, without any additional widgets. And, unfortunately, i found some things that Qt can't do.
    It would be very nice if the QtSoftware will make an additional functionality for such things.

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

    Default Re: How to sendEvent QPaintEvent ?

    Quote Originally Posted by SABROG View Post
    And, unfortunately, i found some things that Qt can't do.
    Ok, such as?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: How to sendEvent QPaintEvent ?

    Quote Originally Posted by wysota View Post
    Ok, such as?
    Like painting over widgets without additional widget and hemorroid with installEventFilter and reimplement paintEvent for all childs. Like create semi-transparent main widget with system titlebar or just titlebar paint from Qt (semi-transparent widget without flag Qt::FramelessWindowHint).

    ---
    More experiments...
    Last edited by SABROG; 28th May 2009 at 09:22.

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

    Default Re: How to sendEvent QPaintEvent ?

    Quote Originally Posted by SABROG View Post
    Like painting over widgets without additional widget and hemorroid with installEventFilter and reimplement paintEvent for all childs.
    I'm sure you'll admit this is not what normally people do :-)

    By the way, look here: http://www.qtcentre.org/forum/showth...ht=post+filter

    Like create semi-transparent main widget with system titlebar or just titlebar paint from Qt (semi-transparent widget without flag Qt::FramelessWindowHint).
    And here: Creating Translucent Windows. For the title bar blame your system - it is not part of the application so it has no control over it.

    Any other requests? :-)
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    SABROG (28th May 2009)

  14. #13
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: How to sendEvent QPaintEvent ?

    Quote Originally Posted by wysota View Post
    I'm sure you'll admit this is not what normally people do :-)

    By the way, look here: http://www.qtcentre.org/forum/showth...ht=post+filter
    Thanks for link, this what we actually doing, but with call QApplication::sendEvent again.

    Quote Originally Posted by wysota View Post
    And here: Creating Translucent Windows. For the title bar blame your system - it is not part of the application so it has no control over it.

    Any other requests? :-)
    With system titelbar i understand. Qt cat draw titlebar from code in QGraphicsWidget for QGraphicsScene. But simple users can't call this painter for Translucent Windows and must write own implementation for this.

    --Updated--
    I post our solution on wiki.crossplatform.ru
    Last edited by SABROG; 28th May 2009 at 12:39.

Similar Threads

  1. QPaintEvent syntax question
    By last2kn0 in forum Newbie
    Replies: 5
    Last Post: 25th January 2008, 20:36
  2. QPaintEvent on button click?
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2007, 08:44
  3. Replies: 4
    Last Post: 26th July 2006, 07:06
  4. Inheritance and QpaintEvent
    By djoul in forum Qt Programming
    Replies: 22
    Last Post: 5th July 2006, 13:56

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.