Resizing pixmaps inside QGraphicsScene when the scene is resized
-
Hi there!
I have a window which looks like this : http://imgur.com/tjhpyOX
What I want to do is a Game of 15 - I have to put multiple images in a grid inside this QGraphicsScene but the thing is, I want them to resize when I resize this window.
The widgets inside the window resize automatically as they're inside a QGridLayout but I cant get the images inside the QGraphicsScene to resize.
How do I do that?Thanks in advance!
-
you could zoom the graphicsview in the resizeEvent. The following code ensures that the image grid (bounding rect) is always visible inside the graphcisview.
@
void MyGraphicsView::resizeEvent(QResizeEvent* event)
{
QGraphicsView::resizeEvent(event);QSize viewportSize = this->viewport().size(); QSize imageGridSize = ...; //size of all images (bounding rect) qreal factor = viewportSize.width() / imageGridSize.width(); if( viewportSize.height() < (imageGridSize * factor).height() ) factor *= viewSize.height() / (imageSize * factor).height(); this->resetTransform(); QTransform transform = this->transform(); transform.scale(factor, factor); this->setTransform(transform);
}
@ -
this may work in some cases... but resizing to the viewport's size is the correct way since this is the visible area where your items are rendered onto.