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 image from file, code works fine but image disappiars very fast.
How can I pause image screen?
And how can I load image in "graphicsView" widget?
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;
QGraphicsPixmapItem item(QPixmap::fromImage(image));
scene.addItem(&item);
ui->graphicsView->setScene(&scene);
ui->graphicsView->show();
}
}
It does not work.
How to fix this?