PDA

View Full Version : Update QGraphicsScene - Best Practice



vinaykusta
4th November 2011, 04:52
Hi,

I have a set of raw image files. Referring to the tutorials, I have written a QImage plugin to read the raw files. and display.
I'm successfully able to display these sequnce of files continuosly. Code is as below.
I would like to know if the approach I have taken is the right one... Is this the practice usually followed.


Ui::MainWindow *ui;
QImage rawImg;
QPixmap *pixmap;
QGraphicsPixmapItem *pixmapItem;
Canvas *scene;

pixmap = new QPixmap(555, 313);
pixmapItem = new QGraphicsPixmapItem();
scene = new Canvas(0,0,798,598);
scene->addItem(pixmapItem);
ui->liveFeedView = new QGraphicsView();
ui->liveFeedView->setScene(scene);
ui->setupUi(this);

QTimer* updateTimer = new QTimer(this);
QObject::connect(updateTimer,SIGNAL(timeout()),thi s,SLOT(doUpdate()));
updateTimer->start(50);

"Canvas" is derived from QGraphicsScene. Finally the slot doUpdate is as below:


if(rawImg.loadFromData(imgData[i]))
{
QPainter painter;
painter.begin(pixmap);
painter.drawImage(0,0,rawImg);
painter.end();
pixmapItem->setPixmap(*pixmap);

ui->liveFeedView->setScene(scene);
qDebug() << "File updated: " << i;
}
i++;