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):
#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
#include <iostream>
#include <QImage>
#include <QPixmap>
using namespace std;
ui(new Ui::Widget)
{
ui->setupUi(this);
mylabel->show(); //
for(int step=0;step<250;step++)
{
da = 3;db=1;dc=.5;
for(int i=0;i<100;i++)
{
for(int j=0;j<100;j++)
{
QRgb colorval;
colorval = qRgb(a,b,c);
myimage.setPixel(j,i,colorval);
//cout << " Setting " << i << " " << j << endl;
}
}
a = a + da;
b = b + db;
c = c + dc;
mylabel->setPixmap(mypixmap);
mylabel->setScaledContents(true);
mylabel->update();
}
}
Widget::~Widget()
{
delete ui;
}
#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
#include <iostream>
#include <QImage>
#include <QPixmap>
using namespace std;
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
mylabel = new QLabel; //
mylabel->show(); //
myimage = QImage(100,100,QImage::Format_RGB32);
for(int step=0;step<250;step++)
{
da = 3;db=1;dc=.5;
for(int i=0;i<100;i++)
{
for(int j=0;j<100;j++)
{
QRgb colorval;
colorval = qRgb(a,b,c);
myimage.setPixel(j,i,colorval);
//cout << " Setting " << i << " " << j << endl;
}
}
a = a + da;
b = b + db;
c = c + dc;
QPixmap mypixmap = QPixmap::fromImage(myimage);
mylabel->setPixmap(mypixmap);
mylabel->setScaledContents(true);
mylabel->update();
}
}
Widget::~Widget()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Bookmarks