PDA

View Full Version : Grid in QGraphicsScene to fit in QGraphicsView while expanding



phenom64
22nd March 2014, 18:58
Hi,

I want to draw a grid (square), and this grid has to remain square and grow up, while the view is expanding.

I used setSceneRect but it is weird. This example below shows what I'm looking for, the width of the windows is larger than the height, so my grid
grow up and remain square.

And I didn't know how to do this with Qt. Bellow I've done it with direct2D...
10160

need your help...

Thanks.

wysota
23rd March 2014, 08:56
The easiest way is to simply scale the view using QGraphicsView::fitInView() called from within resizeEvent of the view.

phenom64
23rd March 2014, 21:32
it seems to work.


GraphicsView->fitInView( scene->sceneRect(), Qt::KeepAspectRatio );

Thanks a lot

phenom64
9th May 2014, 09:28
Hi,

this time, when I drew 1000 squares grid with 1pixel each square, this doesn't fit in my GraphicsView,

I got blank scene... my screen resolution is around 1000 pixels, if I reduced to 800 squares, I got all my grid back.

What I don't understand is I can't draw more than 1000 pixels whatever my GraphicsView's size...

bellow 800 squares fit correctly in 300pixels GraphicsView's size
with 1000 squares all I got is blank even with 900 pixels GraphicsView's size(with my view expanded at maximum)
10345

Any tips please ?

wysota
12th May 2014, 10:11
Please provide a minimal compilable example reproducing the problem.