PDA

View Full Version : update() works fine sometime but not everytime..!!



salmanmanekia
20th August 2008, 08:51
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 ..!!


..
connect(button,SIGNAL(clicked()),training,SLOT(rec ognitionAccept()));
..


#include "Progress.h"
#include "TrainNavigation.h"

void TrainingUI::recognitionAccept()
{
..
progress->showAcceptedProgress();
..
navigate->enableNavigationButtons();
}


void Progress::showAcceptedProgress()
{
qDebug() << "Show Accepted Progress "
..
update();
..
}


void TrainNavigation::enableNavigationButtons()
{
..
playButton->setDisabled(FALSE);
..
}

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

wysota
20th August 2008, 09:15
update() will always be called but it will not always cause paintEvent to be executed.

salmanmanekia
20th August 2008, 09:20
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 :)

bunjee
20th August 2008, 11:05
You can use repaint() to force painting.

salmanmanekia
20th August 2008, 11:06
repaint() doesnt make any difference,still the paintEvent() is not called sometimes

bunjee
20th August 2008, 11:11
What are you trying to achieve ?
Why do you care calling paintEvent if it's not needed ?

wysota
20th August 2008, 11:13
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.

salmanmanekia
20th August 2008, 11:14
Why do you care calling paintEvent if it's not needed ?

who said paintEvent is not needed ,read the first post carefully...!!

salmanmanekia
20th August 2008, 11:22
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 ..??

bunjee
20th August 2008, 11:25
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.

salmanmanekia
20th August 2008, 11:31
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

wysota
20th August 2008, 11:54
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.

salmanmanekia
20th August 2008, 13:29
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...

wysota
20th August 2008, 14:28
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.

salmanmanekia
21st August 2008, 08:18
thanks...i wasnt stopping the timer ,thats why sometime two updates() were running at the same time...:)..

salmanmanekia
21st August 2008, 08:40
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..!!

wysota
21st August 2008, 10:59
Can you post your paintEvent()?

salmanmanekia
21st August 2008, 12:17
PaintEvent Function:
-----------------------

QPainter painter(this);
painter.setPen(QPen(grayBrush, ....
painter.drawEllipse(OUTER_ELLIPSE_X,...

if(trials_completed >= 1)
{
painter.setPen(QPen(greenBrush,30,....
if(trials_completed == 1)
{
qDebug() << "Draws The First Green Sequence ";
..// painting done here
}
else if(trials_completed == 2)
{
qDebug() << "Draws The First Two Green Sequence ";
..// painting done here
}
else if(trials_completed == 3)
{
qDebug() << "Draws The First Three Green Sequence ";
..// painting done here
}
else if(trials_completed == 4)
{
qDebug() << "Draws The Four Green Sequence ";
..
}
}
if (rec_button == FALSE && accept_press == TRUE )
{
..painting done depending on the button press by the user..
}

salmanmanekia
22nd August 2008, 07:28
if any other info is required do tell me...:)

wysota
22nd August 2008, 09:11
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.