I have a QGraphicsScene and a QGraphicsView. I am currently using the QGraphicsView to draw a backgorund image. I have reimplemented the QGraphicsView::drawBackground() function like this:
Qt Code:
  1. def drawBackground(self, painter, rect):
  2. sceneRect = self.sceneRect()
  3. if self.background:
  4. rectf = QRectF(self.background.rect())
  5. painter.drawPixmap(sceneRect, self.background, rectf)
  6. else:
  7. painter.fillRect(rect.intersect(sceneRect), QBrush(Qt.lightGray))
  8. painter.setBrush(Qt.NoBrush)
  9. painter.drawRect(sceneRect)
To copy to clipboard, switch view to plain text mode 
self.background is a QPixmap:
Qt Code:
  1. self.background = QPixmap(':/some_image.png')
To copy to clipboard, switch view to plain text mode 
The problem with this is that if the PNG is not in my .qrc file, the background image does not show up. I would like to make it so that I can use any image I want without having to put it into the .qrc. How would I do this?

I took a look at QGraphicsScene::drawBackground() which requires a QPainter as a parameter. However, I am not sure of how to tell the QPainter which image to use.