Hi all,

i have a little probelm. I wanted to write a renderer and use qt as a frontend. Now my question is, how do i display and update my image _efficently_. As the rendering process needs time there are only a few pixels which gets updated in a certain interval.

I've written a little program which shows how i would solve this problem. But i'm not very happy with this solution because i don't know how much copying of the image is done under the hood. Maybe theres a better way?

Here the code:

Qt Code:
  1. class QMainWin : public QMainWindow
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. QMainWin();
  7.  
  8. private:
  9. QScrollArea *area;
  10. QImage *image;
  11. QLabel *imgLabel;
  12. int x, y;
  13.  
  14. private slots:
  15. void drawPixels();
  16. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. QMainWin::QMainWin()
  2. {
  3. image = new QImage(200, 200, QImage::Format_ARGB32);
  4. imgLabel = new QLabel;
  5. imgLabel->setPixmap(QPixmap::fromImage(*image));
  6.  
  7. area = new QScrollArea;
  8. area->setBackgroundRole(QPalette::Dark);
  9. area->setWidget(imgLabel);
  10.  
  11. setCentralWidget(area);
  12.  
  13. QAction* action = new QAction(tr("Draw something"), this);
  14. connect(action, SIGNAL(triggered()), this, SLOT(drawPixels()));
  15.  
  16. QMenu* menu = menuBar()->addMenu(tr("Drawing"));
  17. menu->addAction(startAction);
  18.  
  19. x = y = 0;
  20. }
  21.  
  22. void QMainWin::drawPixels()
  23. {
  24. for(int i = y; i < y+20; i++)
  25. for(int j = x; j < x+20; j++)
  26. image->setPixel(j, i, qRgb(255, 0, 0));
  27.  
  28. x += 20;
  29. y += 20;
  30.  
  31. // This line is needed, else the picture doesn't get updated
  32. imgLabel->setPixmap(QPixmap::fromImage(*image));
  33. imgLabel->update();
  34. }
To copy to clipboard, switch view to plain text mode 

I've omitted forward declarations, includes and so on.
Sry for the bad english.

Regards
Imons