PDA

View Full Version : Show a lot of QPolygon (hex) in QGraphicsScene with QGraphicsView



Rumo
16th May 2011, 00:45
Hi,

I'm having a problem with the bounds of a map consists of hexagons. The hexagons were added to a QGraphicScene and this is shown in a QGraphicsView. For the first everything is right.

6419

But in my case I want to have a game with pixel detailed unit movements. And so the bounds of the map are not so proper. I want to cut the bounding hexagons so that there's no background color to see.

So my question is: What is the best way to improve the bounds to have a game in which the hexagons are only for land type information and units are able to move pixel accurate.

For my there are two ways. First is to draw "cutted" bound hexagons and the second is to "clip" the QGraphicScene or to setSceneRect. But setSceneRect does'nt work in the right way.

Thank you
Rumo

SixDegrees
16th May 2011, 08:12
Why can't you just fill your scene with slightly more polygons than you need, then set the view to show a smaller region of the scene?

Rumo
16th May 2011, 10:24
I do it similar. I just cut the bounds with setSceneRect. Everything seems ok, when map doesn't fit in QGraphicsView and scroll bars are visible. But when I maximize the main window and no scroll bars of QGraphicsView are visible, the bounds extend to infinity.

6420

Here it can be seen that when window (and QGraphicsView) is extended over the map x-size the bounds aren't cut (in x direction). But I want to cut the bounds ever.

Rumo

Rumo
17th May 2011, 07:50
I just solve the problem with setting the maximumsize of the QGV to the extention of the containing widgets.