2

I was wondering what the most efficient way to paint a mostly-static QWidget with several overplayed, semi-transparent gradients would be. I'm considering two options:

  • Just place all the painting code in the paintEvent function like usual.
  • Paint everything to a QPixmap when resized, and only paint the QPixmap itself in the paintEvent.

I'm imagining the difference in performance between the two would rely heavily on how complicated the drawing code is, but is there a way to test this more quantitatively? Also, does anybody have any advice about which method should be used? (for all I know, the Qt painter does the pixmap caching behind the scenes)

Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
K. Barresi
  • 1,275
  • 1
  • 21
  • 46
  • 4
    "is there a way to test this more quantitatively?", what do you mean? Write some test code and benchmark (fps when doing constant repaints is probably a good measure). – hyde Apr 28 '15 at 16:06
  • Yes, I meant that I was looking for a good way to test the paint performance of each method. I just wasn't sure the best way of going about that, meaning which metric would be best to measure in this situation. – K. Barresi Apr 28 '15 at 16:21
  • 2
    Use QElapsedTimer to measure times. Connect a QTimer with interval 0 to repaint() method to force constant repaints with no delay. You could for example do 1000 repaints and measure total time, if you want it simple. This should get you started, in case nobody steps in to write a more detailed answer. – hyde Apr 28 '15 at 17:07

0 Answers0