PDA

View Full Version : Display Images in QGraphicsView



robertaandrews
12th May 2007, 20:01
I have placed a QGraphicsView widget on a main window and promoted it to
a custom widget.

I have created a scene attached to the view and added a pixmap to the scene.

I then loaded a jpeg image into the scene.

I copied the drawBackdrop method from the Qt Elastic Nodes sample.

I get the backdrop drawn but can not see the loaded image.

I've just started using designer - I can make this work coding by hand,
but I seem to be missing something when trying to get the image to
display when I do a show() on the top level main window generated by designer.

anyone one have a bit of sample code that works that they could share - would be greatly appreciated.:confused:

marcel
12th May 2007, 20:25
Could you post the code sequence in question? Maybe you're doing something wrong there.

Regards

robertaandrews
15th May 2007, 17:30
I have attached a compressed tar file with my attempt at getting an image
into a graphicsviewer widget.

thanks

rob

marcel
15th May 2007, 19:20
Yes, I just tested with:


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsView* w = new QGraphicsView();
QGraphicsScene *scn = new QGraphicsScene( w );
scn->setSceneRect( w->rect() );
w->setScene( scn );
w->setFixedSize( 400, 400 );
QPixmap pix( "c:\\pix_jpg.jpg" );
scn->addPixmap( pix );
w->show();
a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}

( yes, this is a very poor example :) ).

I loaded both your jpeg and some others, and also a png. All were OK.
Maybe you have some problems with your jpeg plug-in. Try loading a png instead.

Anyway, you should look at what pixmap.size() return after you load it.
Regards

marcel
15th May 2007, 19:35
Also ,make sure the path is correct.