Qt QGraphicsView one background image on center
My QGraphicsView
item is a lot bigger than its background image, but I would like that background image to be drawn only once. Now the whole thing is filled with that background image as many times as there is space for it.
So, how c开发者_Go百科an I force that background image to be drawn only once to the center of the view?
Here is the code I'm currently using:
QPalette palette;
palette.setBrush(this->backgroundRole(),QBrush(*myImage));
this->setPalette(palette);
Thank you for your answers!
The QGraphicsView
renders the background in the function drawBackground()
. The default implementation of this fills the views rectangle using the background brush giving the result you are seeing.
You could override drawBackground()
to render an image the way you want but that would mean subclassing QGraphicsView
.
If this isn't an option, you could probably set a QGraphicsPixmapItem
at the lowest Z order in the scene with the image you want.
精彩评论