Hi there,
I would like to create a image (on the fly), fill it with colors and then display it using a QGraphicsScene. I managed to write the code but the pixels that I made blue are not visible. Any ideas on what is wrong?
* part of the view class (the main code regarding the question is in the initializeScene function):
cGeometryViewer
::cGeometryViewer(QWidget *parent
) :{
setScene(m_scene);
}
void cGeometryViewer::setGeometry(cGeometry *geometry)
{
m_geometry = geometry;
initializeScene();
}
void cGeometryViewer::initializeScene()
{
QImage img
(MATRIXWIDTH, MATRIXHEIGHT,
QImage::Format_ARGB32);
//just to find out if it works fill a rectangle with black pixels
for(int x=0; x<100; x++)
for(int y=0; y<100; y++)
img.
setPixel(QPoint(x,y
), Qt
::black);
m_scene->addItem(&pmi);
show();
}
cGeometryViewer::cGeometryViewer(QWidget *parent) :
QGraphicsView(parent)
{
m_scene = new QGraphicsScene(0, 0, MATRIXWIDTH, MATRIXHEIGHT);
setScene(m_scene);
}
void cGeometryViewer::setGeometry(cGeometry *geometry)
{
m_geometry = geometry;
initializeScene();
}
void cGeometryViewer::initializeScene()
{
QImage img(MATRIXWIDTH, MATRIXHEIGHT,QImage::Format_ARGB32);
//just to find out if it works fill a rectangle with black pixels
for(int x=0; x<100; x++)
for(int y=0; y<100; y++)
img.setPixel(QPoint(x,y), Qt::black);
QGraphicsPixmapItem pmi(QPixmap::fromImage(img));
m_scene->addItem(&pmi);
show();
}
To copy to clipboard, switch view to plain text mode
* and part of the main code;
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_geometry = new cGeometry();
m_viewer = new cGeometryViewer(ui->frameMain);
m_viewer->setGeometry(m_geometry);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_geometry = new cGeometry();
m_viewer = new cGeometryViewer(ui->frameMain);
m_viewer->setGeometry(m_geometry);
}
To copy to clipboard, switch view to plain text mode
Thanks in advance!
Rob
Bookmarks