Solved Loading an image file with QGrapchisScene
-
Hi,
I imagine that should be something simple to do, but I am failing to do it.
I want to load an image into a QGraphicsView using a QGraphicsScene, but the image is too big, and I do not know how to make the image fit into the QGraphicsView.
This is what I am doing:
void MainWindow::on_btnLoadFace_clicked() { QString fileName = QFileDialog::getOpenFileName( this, tr("Open Image"), ".", tr("Image Files (*.png *.jpg *.bmp)")); QPixmap pixMap(fileName); face = scene->addPixmap(pixMap); ui->graphicsView->show(); }
scene
is aQGraphicsScene *
, andface
is aQGraphicsPixmapItem *
.I tried
pixMap.scaled(400, 600, Qt::KeepAspectRatio);
just afterQPixmap pixMap(fileName);
, but it made no difference.
Could anyone, please, tell me what is missing?Thanks
-
Hi,
QPixmap::scales returns a new object. Did you use the returned QPixmap ?
-