Question

I am building a node graph in a QGraphicsView and I am currently implementing panning. I used the following question "how to pan images in QGraphicsView" to start but the panning is limited by the scrollbar range.

I also tried the translate method but it gives the same result. The view is limited to a certain rectangle.

I would like to pan without limits, the graph can becomes quite large and it is useful to be able to work in different area of the scene (one graph here, another graph over there, etc).

Was it helpful?

Solution

If you take a look at this video, at the 3 minute mark you'll see the demonstration panning the screen. The application here is one I developed and although it doesn't show it, the real estate of the board appears limitless when panning.

What I did for this was to create a QGraphicsScene of 32000 x 32000 and start the application with the view at the centre of the QGraphicsScene. The test team spent ages trying to pan to the edge of the graphics scene and everyone gave up before getting there - perhaps the scene could have been smaller!

The scroll bar policies are set to off and translation is done by moving the QGraphicsView via its translate function, passing in the delta of either touch, or mouse movement that is applied in the mouseMoveEvent.

Done this way, you need not worry about exceeding the scroll bar range and there was no problem creating a very large QGraphicsScene as it's just a coordinate space.

OTHER TIPS

I came across the same issue. However, setting the scene to something big and leaving it I do not think is the best option. I have developed a dynamic way of changing the scene size so it lets you move freely. You can find it in this other stack overflow answer.

You want to plot graphs. Try out this Qt library - QCustomPlot , it will save you hours of hard work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top