I've created a Graphics View object in my mainwindow.ui file and I'm trying to display an image in that. For TextBrowser objects, I was doing like this
QTextBrowser *textBrowser_Actors = this->findChild<QTextBrowser*>("textBrowser_Actors");
textBrowser_Actors->setText(QString::fromUtf8(movie.get_actors().c_str()));
Similar way, how do I set an image after finding a GraphicsView by the below method?
QGraphicsView* movie_poster = this->findChild<QGraphicsView*>("movie_poster");
I tried the following from googling a bit, but couldn't get it working so far.
QGraphicsScene* scene = new QGraphicsScene();
movie_poster->setScene(scene);
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage("movie.jpg"));
scene->addItem(item);
movie_poster->show();
Edit-1
int main(int argc, char *argv[])
{
std::vector<Movie> movie_vector; // This is where movie DB will be read to, and new movies will be added to
MainWindow w;
w.setWindow(movie_vector[0]); // calling setWindow with first movie
w.show();
return a.exec();
}
//setWindow definition
void MainWindow::setWindow(Movie &movie) {
// Next two lines gets the textBrowser object and set its value to movie title
QTextBrowser *textBrowser_Title = this->findChild<QTextBrowser*>("textBrowser_Title");
textBrowser_Title->setText(QString::fromUtf8(movie.get_title().c_str()));
// This is where I'm trying to get GraphicsView object and set an image in it.
QGraphicsView* movie_poster = this->findChild<QGraphicsView*>("movie_poster");
QGraphicsScene* scene = new QGraphicsScene();
movie_poster->setScene(scene);
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap("C:\Users\Name\Desktop\codes\Qt\MovieDB\titanic.jpg"));
scene->addItem(item);
movie_poster->show();
}