PDA

View Full Version : problem with QGraphicsPixmapItem



JustJ
3rd November 2014, 23:30
Hello everyone,
I am trying to display an image using QGraphicsView but all I get is a blank window.
Here is the code:


int main(int argc, char *argv[])
{
QApplication a(argc, argv)
QGraphicsView view;
QGraphicsScene* scene = new QGraphicsScene(QRect(0, 0, 600, 400));
QPixmap Pix("king.png");
//does not work either
//QGraphicsPixmapItem *item1 = scene->addPixmap(Pix);
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(Pix);
scene->addItem(item);
view.setScene(scene);
view.show();
return a.exec();
}


I think that I'm missing something obvious, but still I'm unable to find it on my own.
Any suggestions?

JustJ
4th November 2014, 06:11
solved.
Relative path does not work for me. Had to use absolute path.

QPixmap Pix("/home/justas/graphics_view_test/king.png");

anda_skoa
4th November 2014, 09:14
Relative paths depend on the current working directory of the application.

Cheers,
_