PDA

View Full Version : How to add a picture to a Graphicsview



Malek
17th August 2010, 17:02
Hello
My question today is:
How to add a picture to a Graphicsview .
I want to make it in the same size of Graphicsview.
Or ,if possible, I want to make it zoom-able.

Regards,

Lykurg
17th August 2010, 17:11
QGraphicsScene::addPixmap().

Urthas
17th August 2010, 18:58
Or, you can instantiate a QGraphicsPixmapItem and give it to QGraphicsScene::addItem(). To be clear, you don't add anything to a QGraphicsView, which is nothing more than a "porthole", if you like, onto the QGraphicsScene, which contains all your pictures etc.

Malek
22nd August 2010, 00:58
Thanks Lykurg .Thanks Urthas.

My Partner has been found it.

void MainWindow::on_pushButton_clicked()
{
QGraphicsScene *scene = new QGraphicsScene();
QPixmap m("/home/MALEK/QT-Creator/PROJECTs/soso/bomb.jpeg");
scene->setBackgroundBrush(m.scaled(100,100,Qt::IgnoreAspe ctRatio,Qt::SmoothTransformation));

ui->graphicsView->setScene(scene);
}

}

But We still don't Know How to make it in the same size of white rectangle.And how to make it zoom-able.


Thank you very much .

Lykurg
22nd August 2010, 09:37
You can subclass QGraphicsView and in its paintEvent draw your picture scaled to the bounding rect.

aamer4yu
23rd August 2010, 01:08
Check the 40000 chips demo in Qt Demos.. you will get an idea how to zoom in / zoom out..