PDA

View Full Version : displaying scaled image



deck99
16th March 2011, 05:04
hi........
i have a image where i want to show it on specified Qgraphicsview on the mainwindow. the image display out of specified qgraphicsview with scroll bars. i want the image to show on that specific qgraphicsview.

chem.jpg is the image



QGraphicsView* w = new QGraphicsView();
QGraphicsScene *scn = new QGraphicsScene( w );

w->setScene( scn );
QPixmap pix("/home/karl/Desktop/chem.jpg" );
scn->addPixmap( pix );
w->show();

stampede
16th March 2011, 07:57
If I understand correctly, you want to resize the image to match the size of graphics view ? Have you tried QPixmap::scaled (http://doc.qt.nokia.com/latest/qpixmap.html#scaled) ?

deck99
16th March 2011, 09:50
yeah, i want the image to be displayed in the Qgraphicsview. Can u tell me whr to use Qpixmap::scaled()

stampede
17th March 2011, 07:50
What have you tried so far ?

deck99
17th March 2011, 15:06
Can u tell me where i should modify my code to display the image in specified graphicsview?

szisziszilvi
18th March 2011, 09:32
I think this would be something like scn->addPixmap( pix.scaled(w->with(),w->height()) );
but check the documentation for the proper answer.