I have created an application with a countdown timer and the number of seconds remaining is displayed in a QLabel widget inside the Graphics View Framework.

In the code below time_label is a QLabel and time_bar is a QProgressBar. Both widgets are wrapped inside a QGraphicsProxyWidgets which are displayed on a QGraphicsScene. The method timerEvent is triggered every 1000ms. The onTestOver() method kills the timer once the time is up. I had left out the irrelevant code on purpose.

Qt Code:
  1. void TestPlan::timerEvent(QTimerEvent* tick)
  2. {
  3. time_bar->setValue(time_bar->value()+1);
  4.  
  5. int max = time_bar->maximum();
  6. int val = time_bar->value();
  7.  
  8. int time_left = max - val;
  9. qDebug() << time_left;
  10.  
  11. if (time_left > 0)
  12. {
  13. time_label->setText(tr("%1 seconds remaining").arg(time_left));
  14. }
  15. else
  16. {
  17. time_label->setText(tr("Time is up!"));
  18. onTestOver();
  19. }
  20. }
To copy to clipboard, switch view to plain text mode 

In Qt Creator's "Application Output" I can see that timerEvent() is called every second so the timer works fine:

Qt Code:
  1. 14
  2. 13
  3. 12
  4. 11
  5. 10
  6. 9
  7. 8
  8. 7
  9. 6
  10. 5
  11. 4
  12. 3
  13. 2
  14. 1
  15. 0
To copy to clipboard, switch view to plain text mode 

However the output on the application whether using Debug or Release build I see the count down from 14 to 12, 11 is skipped, then from 10 to 5, 4 is skipped again, and the from 3 to 0.

I though maybe the QLabel updates slowly and I tried in increase the time per interval to 2000ms, but had the same result. The progressbar which also updates by this method, updates correctly every second. It is just the QLabel that sometimes seems to skip an update.

Any ideas on how I can make the QLabel widget to update correctly?