PDA

View Full Version : use a picture as a background in a QGraphicsView



di_zou
25th March 2010, 19:57
I have a QGraphicsView, and I would like to use a .tif image as a background for it. I am assuming I have to rewrite the drawBackground() function, but how would I rewrite it?
I do not want to add the image as a QGraphicsPixmapItem to my QGraphicsScene and then set the image to (0,0) and scale it so it takes up my QGraphicsView background. I would like to do all this inside the QGraphicsView class.

aamer4yu
26th March 2010, 05:08
I am assuming I have to rewrite the drawBackground() function,
You are right. You will need to subclass QGraphicsView and override the drawbackground function in your class.

Also you can try stylesheets. view->setStyleSheet("background-image : url("...."));

Hope this helps :)

di_zou
29th March 2010, 15:43
Style sheets is not quite what I wanted so I did by reqriting the drawBackground() function.

This is what I did:



sceneRect = self.sceneRect()

pic = QPixmap(":/images/68799212.png")
rectf = QRectF(pic.rect())
painter.drawPixmap(sceneRect, pic, rectf)


Thanks!