PDA

View Full Version : Setting the scene size in QGraphicsView



Valheru
25th October 2007, 07:59
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?

wysota
25th October 2007, 08:08
You can pass the size of the scene to the constructor of the scene or use QGraphicsScene::setSceneRect().

Valheru
26th October 2007, 20:03
Thanks, passing it to the constructor did it. setSceneRectangle() wasn't working for some reason, that was one of the things I'd tried.

wysota
26th October 2007, 22:50
When did you use it?

Valheru
11th November 2007, 14:16
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.

wysota
11th November 2007, 15:03
You must have set the positions incorrectly. Hard to say withouth seeing the actual code...