Results 1 to 2 of 2

Thread: QGraphicsScene QPixmap background

  1. #1
    Join Date
    Jul 2010
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Question QGraphicsScene QPixmap background

    Hi All,

    I am trying to load a pixmap as a background for a QGraphics scene using this code:

    QString backGround = ":/Scope.png";
    scopeScene->setBackgroundBrush(QBrush(QImage(backGround)));

    My scene size is 500 x 500. When I set the scene with 0,0 at topleft and 500,500 height width, the background image displays properly.
    ( scopeScene->setSceneRect(0,0,500,500); )

    But I need to offset the scene coords using "scopeScene->setSceneRect(-250,-250,500,500); " so that it extends from -250 to 250 instead of 0 - 500.

    When I do that, the background image is offset wrong and looks like each quadrant gets a different piece of the image, instead of one continuous image.

    How do I offset the screneRect and still load the background image centered in my view?

    Thank you in advance,

    tim

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,543
    Thanks
    13
    Thanked 1,577 Times in 1,506 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QGraphicsScene QPixmap background

    You can customise how the background brush is drawn in QGraphicsScene::drawBackground((). You probably want the QGraphicsView version of these functions, or a different viewport widget, if you want to keep the image in the view.

Similar Threads

  1. QPixmap as background of QWidget
    By Alan_K in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2013, 15:03
  2. QPixmap's background
    By Dopt in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2012, 15:20
  3. Rendering QGraphicsScene to QPixmap to save
    By Rooster in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2009, 05:24
  4. Position in a QPixMap created from a QGraphicsScene
    By stevel in forum Qt Programming
    Replies: 8
    Last Post: 8th April 2009, 22:39
  5. QPixmap display on QGraphicsScene
    By febil in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2009, 09:27

Tags for this Thread

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.