Results 1 to 4 of 4

Thread: strange behavior of paintEvent

  1. #1
    Join Date
    Jun 2009
    Posts
    74
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Question strange behavior of paintEvent

    platform :QT4.6,QT4.7 linux

    Hi, All,

    I got a very strange problem about paintEvent.
    Here is my code

    Qt Code:
    1. ....
    2. status = true; //set status to true by default
    3. ....
    4.  
    5. void MainWindow::paintEvent(QPaintEvent * event )
    6. {
    7. qDebug()<<"paintEvent";
    8.  
    9. QMainWindow::paintEvent(event);
    10. QPainter p(this);
    11. if(status)
    12. p.drawText(110,110,"hello");
    13. else
    14. p.drawText(110,110,"world");
    15. }
    16.  
    17. void MainWindow::on_pushButton_clicked()
    18. {
    19. if(!status)
    20. status = true;
    21. else
    22. status = false;
    23. }
    To copy to clipboard, switch view to plain text mode 

    Here is my steps:
    1. start app , on the window it shows "hello"
    2. click button, status changed to false
    3. move the window to the edge of the screen ,until it become invisible.
    4. move the window back to the center of the screen
    5. from debug info,I can see that paintEvent has been called,
    but what puzzled me is that in the window, it still shows "hello" !!!
    6. minimize the window and the raise it again, the window also still shows "hello"
    7. resize the window ,now it shows "world"

    any ideas about it ?
    Thanks in advance for your help.

    Best regards,
    hb

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: strange behavior of paintEvent

    I guess status is a member variable of MainWindow?
    Can you put the value of status in the paint event debug message and see what it actually is?

    For you clicked slot, you can also write this:
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. status = !status;
    4. update(); // updates the widget
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to tbscope for this useful post:

    hashb (30th August 2010)

  4. #3
    Join Date
    Jun 2009
    Posts
    74
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default Re: strange behavior of paintEvent

    Hi tbscope,

    it works after add update(), Thanks a lot
    but I am still wondering the issue why resize can refresh the window but others can not, in all cases the paintEvent have been called.

    Best regards,
    hb

  5. #4
    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: strange behavior of paintEvent

    It's because only the part of the widget that needs redrawing is actually redrawn (regardless of the code executed by the paint event). Check the rectangle contained in the QPaintEvent object to see what will actually be redrawn.
    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.


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

    hashb (30th August 2010)

Similar Threads

  1. QAudioInput example strange behavior
    By m15ch4 in forum Qt Programming
    Replies: 0
    Last Post: 13th August 2010, 06:55
  2. Strange thing after override paintEvent function
    By Sheng in forum Qt Programming
    Replies: 9
    Last Post: 20th February 2009, 16:44
  3. Strange behavior of QSyntaxHighlighter in Qt3
    By lorebett in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2009, 14:50
  4. Strange resize behavior
    By Lykurg in forum Newbie
    Replies: 3
    Last Post: 9th January 2007, 13:56
  5. scrollbars strange behavior
    By siniy in forum Qt Programming
    Replies: 6
    Last Post: 29th December 2006, 10:27

Tags for this Thread

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.