View an image on QGraphicsView from resources
-
Hi, I'm trying to view an image on QGraphicsView from resources using QPixMap, but I don't know how to load it from it.
I found some code on the internet, but it's using QFileDialog, not resources.
Heres the code:void MainWindow::on_pushButton_clicked() { QString filename = QFileDialog::getOpenFileName(this, tr("Load Image"), mResourceDir, tr("Images (*.png *.jpg)")); if (filename.isEmpty()) { return; } QPixmap p(filename); if (! ui->graphicsView->scene()) { qDebug() << "No Scene!"; QGraphicsScene *scene = new QGraphicsScene(this); ui->graphicsView->setScene(scene); } ui->graphicsView->scene()->addPixmap(p); }
-
Hi,
Use the qrc path:
QPixmap pixmap(":/myfile.png");