Setting the scene size in QGraphicsView
I am currently reading the contents of a *.DHW file (storing a collection of points which make up the strokes of handwritten text) and displaying the contents in a QGraphicsScene/View. However, since you don't start writing at the margins, the QGraphicsScene is never set to the actual size of the paper. And the QGraphicsScene sets it's boundaries according to what it contains. I have been struggling with setGeometry() and such functions, but I still can't get the scene to display properly.
How can I set the size of the scene arbitrarily? I need to get the scene to display the whitespace margins of the paper as well as the text. Also, when zooming in and out it is also imperative that the actual paper size is maintained, as opposed to the default QGraphicsScene behavior which adds in whitespace when you zoom out using the scale() function, and cuts off paper when you zoom in.
Has anyone done something like this before?
Re: Setting the scene size in QGraphicsView
You can pass the size of the scene to the constructor of the scene or use QGraphicsScene::setSceneRect().
Re: Setting the scene size in QGraphicsView
Thanks, passing it to the constructor did it. setSceneRectangle() wasn't working for some reason, that was one of the things I'd tried.
Re: Setting the scene size in QGraphicsView
Re: Setting the scene size in QGraphicsView
I was trying to set the size of the view loading the contents of the file to the parameters reported by teh file ( the DHW file format contains the width and height data of the file. Using setSceneRectangle() after loading the file wouldn't update the scene, at least not like I wanted it to. The text still originated at the top left corner, instead of updating so that the text moved slightly to the right and down. I tried various combinations of positive and negative offset values, nothing worked.
Re: Setting the scene size in QGraphicsView
You must have set the positions incorrectly. Hard to say withouth seeing the actual code...