Hello Everyone,

I am manipulating a rectangular array pixel-by-pixel with QImage and setpixel. Next, I convert the QImage to a QPixmap, and display it through a QLabel. This process works pretty well in itself, but, I would like to be able to manipulate the image's pixels over and over, and display the "updated" Qimage (or Qpixmap) file in the label.

Right now, the QLabel remains white/blank until the for.. loop it is in, finishes. Instead, I'd like to see the changed pixmap after each 'step' within the for loop.

Any suggestions? Is there a method to successfully output the QImage in my QLabel after each loop through the step loop? The ideal result would be a Qlabel that displays the Qpixmap which, after each time through the for (step<numbstep) loop, the color is slightly modified via adjusting the R G B values. Right now, it only outputs the "final" color. (Code Below):


Qt Code:
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. #include <QLabel>
  4. #include <iostream>
  5. #include <QImage>
  6. #include <QPixmap>
  7.  
  8.  
  9. using namespace std;
  10.  
  11.  
  12. Widget::Widget(QWidget *parent) :
  13. QWidget(parent),
  14. ui(new Ui::Widget)
  15. {
  16. ui->setupUi(this);
  17.  
  18. mylabel = new QLabel; //
  19. mylabel->show(); //
  20.  
  21. myimage = QImage(100,100,QImage::Format_RGB32);
  22.  
  23. for(int step=0;step<250;step++)
  24. {
  25. da = 3;db=1;dc=.5;
  26.  
  27. for(int i=0;i<100;i++)
  28. {
  29. for(int j=0;j<100;j++)
  30. {
  31.  
  32. QRgb colorval;
  33. colorval = qRgb(a,b,c);
  34.  
  35. myimage.setPixel(j,i,colorval);
  36. //cout << " Setting " << i << " " << j << endl;
  37. }
  38.  
  39. }
  40. a = a + da;
  41. b = b + db;
  42. c = c + dc;
  43.  
  44. QPixmap mypixmap = QPixmap::fromImage(myimage);
  45.  
  46. mylabel->setPixmap(mypixmap);
  47. mylabel->setScaledContents(true);
  48. mylabel->update();
  49.  
  50. }
  51. }
  52.  
  53. Widget::~Widget()
  54. {
  55. delete ui;
  56. }
To copy to clipboard, switch view to plain text mode