I need to create a rapidly refreshing widget, updating at around 60Hz.

I have a prototype, and it seems to lag (skip a frame) every 5-20 frames.

I would guess that one of two things is happening:
- The monitor refresh rate of 60Hz is not synchronized with the applications refresh, or
- The widget does not actually update every 6ms


The application is meant to flicker between two gradients rapidly. I have made the paintEvent as simple as possible:
Qt Code:
  1. void Flickerer::paintEvent(QPaintEvent*)
  2. {
  3. p->begin(this);
  4. if(showingG1)
  5. p->drawPixmap(*rect, *buffer1);
  6. else
  7. p->drawPixmap(*rect, *buffer2);
  8. p->end();
  9. }
To copy to clipboard, switch view to plain text mode 

A link to the prototype, if it will help (use preset 2 @ 30-60Hz).


How can I make the lag go away? Is there a way to synchronize to the screen's refresh? Or is there a method faster than drawPixmap()? Perhaps having two widgets, then just showing/hiding one of them on every update?

Thanks!