Results 1 to 7 of 7

Thread: How can I make size of QGraphicsScene smaller?

  1. #1
    Join Date
    Apr 2007
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How can I make size of QGraphicsScene smaller?

    Hi!
    I have some problem...

    There are a lot of items on the scene. Their size and arrangement can dynamically vary. But in this case the size of a scene always automatically increase. If the area which items take has decreased, the sizes of the scene does not vary. How is it possible to manage it?

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

    Default Re: How can I make size of QGraphicsScene smaller?

    After moving an item calculate the bounding rectangle all items occupy by using QRectF::united() on boundingRect()s and resize the scene accordingly.

    Of course you may optimise calculations by comparing the original scene size and the element position prior and after a move.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I make size of QGraphicsScene smaller?

    Hey wysota,,,, he cud also use QGraphicsScene::itemsBoundingRect instead of calculating the united on boiunding rects himself , isnt it ???

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

    Default Re: How can I make size of QGraphicsScene smaller?

    Yes, of course. It could be a bit slower though, but unless there are many many items in the scene, it shouldn't matter.

  5. #5
    Join Date
    Apr 2007
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can I make size of QGraphicsScene smaller?

    Thanks, It's works =)
    I used
    Qt Code:
    1. scene->setSceneRect(0, 0, scene->itemsBoundingRect().width() + offset, scene->itemsBoundingRect().height() + offset);
    To copy to clipboard, switch view to plain text mode 

    It's slow, but I don't know other way

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

    Default Re: How can I make size of QGraphicsScene smaller?

    As I mentioned before, cache the result from a previous call and update it when an item is moved (based on the move itself).

  7. #7
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can I make size of QGraphicsScene smaller?

    Prefer this:

    Qt Code:
    1. scene->setSceneRect(scene->itemsBoundingRect());
    To copy to clipboard, switch view to plain text mode 

    The itemsBoundingRect() function finds the actual bounding rect, and that might not be at (0, 0). If you force the scene rect to be (0, 0, width, height), you're bound to have items outside the scene.
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

Similar Threads

  1. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 11:43
  2. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 06:57
  3. Replies: 1
    Last Post: 24th October 2006, 17:40
  4. QTreeView font size not being set
    By forrestfsu in forum Qt Tools
    Replies: 2
    Last Post: 12th October 2006, 14:53
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 23:14

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.