Here is my code:
void MainWindow::on_actionOpen_Image_triggered() { QString fileName = QFileDialog::getOpenFileName(this,"Open Image File",QDir::currentPath()); if(!fileName.isEmpty()) { QImage image(fileName); if(image.isNull()) { QMessageBox::information(this,"Image Viewer","Error Displaying image"); return; } QGraphicsScene scene; QGraphicsView view(&scene); QGraphicsPixmapItem item(QPixmap::fromImage(image)); scene.addItem(&item); view.show(); }
}
I want to display an image from a file, the code works fine, but the images disappear very quickly.
How to pause image display?
And how to load an image into the "graphicsView" widget?
My code is:
void MainWindow::on_actionOpen_Image_triggered() { QString fileName = QFileDialog::getOpenFileName(this,"Open Image File",QDir::currentPath()); if(!fileName.isEmpty()) { QImage image(fileName); if(image.isNull()) { QMessageBox::information(this,"Image Viewer","Error Displaying image"); return; } QGraphicsScene scene; QGraphicsPixmapItem item(QPixmap::fromImage(image)); scene.addItem(&item); ui->graphicsView->setScene(&scene); ui->graphicsView->show(); } }
This does not work.
How to fix it?
source share