Results 1 to 3 of 3

Thread: Question about drawing background images in a QGraphicsScene and QGraphicsView

  1. #1
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Question about drawing background images in a QGraphicsScene and QGraphicsView

    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.

  2. #2
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Question about drawing background images in a QGraphicsScene and QGraphicsView

    Figured this out. Just me being stupid...

  3. #3
    Join Date
    Apr 2012
    Posts
    14
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Thumbs up Re: Question about drawing background images in a QGraphicsScene and QGraphicsView

    How to do this.?


    Added after 11 minutes:


    Finally found it.
    Last edited by karthic; 28th April 2012 at 08:58.

Similar Threads

  1. Question about behavior of QGraphicsView/QGraphicsScene
    By kennethadammiller in forum Newbie
    Replies: 0
    Last Post: 22nd July 2010, 09:56
  2. QGraphicsView/QGraphicsScene rendering question
    By onurozcelik in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2010, 11:23
  3. Replies: 0
    Last Post: 8th April 2010, 16:06
  4. Replies: 0
    Last Post: 6th April 2009, 01:20
  5. Drawing the background of QGraphicsView
    By aknuds1 in forum Qt Programming
    Replies: 13
    Last Post: 9th March 2007, 14:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.