PDA

View Full Version : QGraphicsScene background



goldhappywang
28th April 2009, 03:18
hi all:
I set a file(*.jpg) at the background of QGraphicsScene, but the picture as tiling on the scene , I want to tensilie the picture on the scene, what to do it?
thanks a lot.
the code :

int screen_width = QApplication::desktop()->width();
int screen_height = QApplication::desktop()->height();

scene = new QGraphicsScene(0,0,screen_width,screen_height);
airview = new QGraphicsView();
setCentralWidget(airview);
QPixmap pim("./images/airport.jpg");
scene->setBackgroundBrush(pim.scaled(screen_width,screen_ height,Qt::IgnoreAspectRatio,Qt::SmoothTransformat ion));
airview->setScene(scene);

aamer4yu
28th April 2009, 05:12
You can try scaling the pic to the sceneRect.
Other way round is to inherit the scene, and draw the background pixmap yourself. Have a look at QGraphicsScene::drawBackground

goldhappywang
28th April 2009, 07:57
the class QGraphicsScene draw background as tiles ,I don't know how to rewrite the drawBackground()
the pixmap in the center of the scene