Results 1 to 20 of 20

Thread: update() works fine sometime but not everytime..!!

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question update() works fine sometime but not everytime..!!

    Hi,
    I have implemented a piece of code in which i have called update() function to be called on a signal of a button clicked() ,some time the update() function is called and paintEvent() works but sometime without following and sequence it doesnt work ...its very surprising ..i have also inclucded some debug statements ,the code is posted below..any help would be appreciated ..!!

    Qt Code:
    1. ..
    2. connect(button,SIGNAL(clicked()),training,SLOT(recognitionAccept()));
    3. ..
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "Progress.h"
    2. #include "TrainNavigation.h"
    3.  
    4. void TrainingUI::recognitionAccept()
    5. {
    6. ..
    7. progress->showAcceptedProgress();
    8. ..
    9. navigate->enableNavigationButtons();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Progress::showAcceptedProgress()
    2. {
    3. qDebug() << "Show Accepted Progress "
    4. ..
    5. update();
    6. ..
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void TrainNavigation::enableNavigationButtons()
    2. {
    3. ..
    4. playButton->setDisabled(FALSE);
    5. ..
    6. }
    To copy to clipboard, switch view to plain text mode 

    both the function (i.e TrainNavigation::enableNavigationButtons() and Progress::showAcceptedProgress() ) are always called but in showAccepetedProgress ...
    update() is called sometime ...

  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: update() works fine sometime but not everytime..!!

    update() will always be called but it will not always cause paintEvent to be executed.

  3. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update() works fine sometime but not everytime..!!

    hmm..and why is so,i mean what factors decide when paintEvent() should be called on update and when it shouldnt..?
    thanks for the info..i didnt knew about this fact

  4. #4
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: update() works fine sometime but not everytime..!!

    You can use repaint() to force painting.

  5. #5
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update() works fine sometime but not everytime..!!

    repaint() doesnt make any difference,still the paintEvent() is not called sometimes

  6. #6
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: update() works fine sometime but not everytime..!!

    What are you trying to achieve ?
    Why do you care calling paintEvent if it's not needed ?

  7. #7
    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: update() works fine sometime but not everytime..!!

    Quote Originally Posted by salmanmanekia View Post
    hmm..and why is so,i mean what factors decide when paintEvent() should be called on update and when it shouldnt..?
    If the widget is not visible, there is no point repainting it. When a repaint is already scheduled, there is no point in scheduling another one.

  8. #8
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update() works fine sometime but not everytime..!!

    Quote Originally Posted by bunjee View Post
    Why do you care calling paintEvent if it's not needed ?
    who said paintEvent is not needed ,read the first post carefully...!!

  9. #9
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update() works fine sometime but not everytime..!!

    Quote Originally Posted by wysota View Post
    If the widget is not visible, there is no point repainting it. When a repaint is already scheduled, there is no point in scheduling another one.
    In my scenario widget is visible ,as i havent made it unvisible so i suppose it is visible by default.. i think my problem is regarding the second point i.e

    When a repaint is already scheduled, there is no point in scheduling another one.
    actually i am repainting continuously because i want to draw a progress bar which moves continuously but if the button is clicked then i want that progress bar to stop there and instead draw a progress status which means repaint again...
    so how to solve this ..??

  10. #10
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: update() works fine sometime but not everytime..!!

    Like wysota said, paintEvent is called when it needs to.

    You have to dissociate your model and your view.
    If you're using paintEvent to do something else than painting related operations that's a bad design.

  11. #11
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update() works fine sometime but not everytime..!!

    If you're using paintEvent to do something else than painting related operations that's a bad design.
    i have only painted in my paintEvent as supposedly should be in a good design...
    and also i am updating because i want to update the view...so it is also a requirement

  12. #12
    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: update() works fine sometime but not everytime..!!

    Quote Originally Posted by salmanmanekia View Post
    actually i am repainting continuously because i want to draw a progress bar which moves continuously
    There is no such thing as doing something continuously in computers. Everything is digitized and quantified.

    but if the button is clicked then i want that progress bar to stop there and instead draw a progress status which means repaint again...
    so how to solve this ..??
    When you change the value of the progress bar, call update(). When you click the button - call update(). Never call update in other circumstances. Remember to allow events to be processed in the meantime.

  13. #13
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update() works fine sometime but not everytime..!!

    There is no such thing as doing something continuously in computers. Everything is digitized and quantified.
    hmm...what i meant was that that it is being updated in 1 sec through timer...so that is what is continous..
    When you change the value of the progress bar, call update(). When you click the button - call update().
    to be precise i am calling it only in these two situation ,no More no Less,so why does it not update or calls paintEvent everytime...

  14. #14
    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: update() works fine sometime but not everytime..!!

    So what does your code for changing the progress value and clicking the button look like? What is the timer connected to? If you have a custom paintEvent, please post it here as well.

  15. #15
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update() works fine sometime but not everytime..!!

    thanks...i wasnt stopping the timer ,thats why sometime two updates() were running at the same time.....

  16. #16
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update() works fine sometime but not everytime..!!

    i have one more question regarding the update and paintEvent(), my program is running fine but when i debug the code i see some unwanted behaviuor actually i want to draw one thing lets call it 'A' initially and wanted to draw other things depending on users input lets say it 'B,C,D...'..
    now 'A' should always be drawn no matter what 'B' ,'C' or 'D' is drawn but when i update it redraws A again and again..which is not required ,i only want the paintEvent to draw 'B','C' or 'D' for me not 'A' again and again ..but since it updates the view so to see 'A' again i have to redraw it every time...i want to some how define it in such a way that if 'A' is drawn one time it remains on screen no matter how many other updates are done..
    i hope you understand..!!

  17. #17
    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: update() works fine sometime but not everytime..!!

    Can you post your paintEvent()?

  18. #18
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update() works fine sometime but not everytime..!!

    PaintEvent Function:
    -----------------------
    Qt Code:
    1. QPainter painter(this);
    2. painter.setPen(QPen(grayBrush, ....
    3. painter.drawEllipse(OUTER_ELLIPSE_X,...
    4.  
    5. if(trials_completed >= 1)
    6. {
    7. painter.setPen(QPen(greenBrush,30,....
    8. if(trials_completed == 1)
    9. {
    10. qDebug() << "Draws The First Green Sequence ";
    11. ..// painting done here
    12. }
    13. else if(trials_completed == 2)
    14. {
    15. qDebug() << "Draws The First Two Green Sequence ";
    16. ..// painting done here
    17. }
    18. else if(trials_completed == 3)
    19. {
    20. qDebug() << "Draws The First Three Green Sequence ";
    21. ..// painting done here
    22. }
    23. else if(trials_completed == 4)
    24. {
    25. qDebug() << "Draws The Four Green Sequence ";
    26. ..
    27. }
    28. }
    29. if (rec_button == FALSE && accept_press == TRUE )
    30. {
    31. ..painting done depending on the button press by the user..
    32. }
    To copy to clipboard, switch view to plain text mode 

  19. #19
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: update() works fine sometime but not everytime..!!

    if any other info is required do tell me...

  20. #20
    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: update() works fine sometime but not everytime..!!

    Quote Originally Posted by salmanmanekia View Post
    now 'A' should always be drawn no matter what 'B' ,'C' or 'D' is drawn but when i update it redraws A again and again..which is not required
    Why is it not required? You said it should be drawn each time.

    ,i only want the paintEvent to draw 'B','C' or 'D' for me not 'A' again and again ..but since it updates the view so to see 'A' again i have to redraw it every time...i want to some how define it in such a way that if 'A' is drawn one time it remains on screen no matter how many other updates are done..
    This is not possible. You have to draw it every time.

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.