You current design works; loading the images once, upon initialization, instead of every time the widget is painted is the right way. I was not suggesting changing that, quite the contrary.

Instead of allocating QImages on the heap, you could allocate QPixmaps directly with the MiaClasse:

Qt Code:
  1. class MiaClasse /* ... */ {
  2. /* ... */
  3. private:
  4. QPixmap image1;
  5. QPixmap image2;
  6. }
  7.  
  8. void MiaClasse::init(){
  9. image1.load("resources/images/image1.png");
  10. image2.load("resources/images/image2.png");
  11. blink = false;
  12. }
  13.  
  14. void MiaClasse::letItBlink(){
  15. blink = !blink;
  16. update(); // Call this instead of QWidget::repaint()
  17. }
  18.  
  19. void MiaClasse:: paintEvent(QPaintEvent *) {
  20. QPainter painter(this);
  21. painter.drawPixmap(155, 130, image1);
  22. if(blink)
  23. painter.drawPixmap(155, 130, image2);
  24. }
To copy to clipboard, switch view to plain text mode