Results 1 to 6 of 6

Thread: Setting the scene size in QGraphicsView

  1. #1
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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().

  3. The following user says thank you to wysota for this useful post:

    Valheru (26th October 2007)

  4. #3
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting the scene size in QGraphicsView

    When did you use it?

  6. #5
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting the scene size in QGraphicsView

    You must have set the positions incorrectly. Hard to say withouth seeing the actual code...

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 20:50
  2. Size of QGraphicsView
    By IsleWitch in forum Newbie
    Replies: 10
    Last Post: 10th October 2007, 12:09
  3. setting needle size in qwtCompass
    By user in forum Qwt
    Replies: 4
    Last Post: 22nd July 2007, 23:40
  4. Replies: 3
    Last Post: 30th January 2007, 07:35
  5. How to use QGraphicsView and Scene right ...
    By Mike in forum Qt Programming
    Replies: 6
    Last Post: 22nd January 2007, 08:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.