PDA

View Full Version : QGraphicsScene QPixmap background



twells5
3rd June 2016, 12:59
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

ChrisW67
4th June 2016, 23:19
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.