Results 1 to 3 of 3

Thread: use a picture as a background in a QGraphicsView

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

    Default use a picture as a background in a QGraphicsView

    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.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: use a picture as a background in a QGraphicsView

    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

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

    Default Re: use a picture as a background in a QGraphicsView

    Style sheets is not quite what I wanted so I did by reqriting the drawBackground() function.

    This is what I did:

    Qt Code:
    1. sceneRect = self.sceneRect()
    2.  
    3. pic = QPixmap(":/images/68799212.png")
    4. rectf = QRectF(pic.rect())
    5. painter.drawPixmap(sceneRect, pic, rectf)
    To copy to clipboard, switch view to plain text mode 

    Thanks!

Similar Threads

  1. How to Transparent QGraphicsView widget Background?
    By ashukla in forum Qt Programming
    Replies: 31
    Last Post: 6th March 2010, 11:35
  2. Replies: 6
    Last Post: 13th January 2010, 18:44
  3. Replies: 0
    Last Post: 6th April 2009, 01:20
  4. Replies: 1
    Last Post: 24th August 2007, 11:18
  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.