Results 1 to 4 of 4

Thread: how to make the QGraphicsScene resize automaticly

  1. #1
    Join Date
    Apr 2013
    Posts
    1
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default how to make the QGraphicsScene resize automaticly

    I put a QGraphicsItem on a QGraphicsScene。When the item enlarge,the Scene will enlarge automaticly.
    But the problem is when the item shrink, the Scene can not shrink automaticly.
    who can give me some advice to make the QGraphicsScene resize automaticly whenever the item enlarge or shrink?
    I will be very very grateful...

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to make the QGraphicsScene resize automaticly

    who can give me some advice to make the QGraphicsScene resize automaticly whenever the item enlarge or shrink?
    By default scene will grow when items are added or moved, by will not shrink when items are removed or moved. Scene should be explicitly shrinked using code like this.
    Qt Code:
    1. //Calculates and returns the bounding rect of all items on the scene.
    2. //This function works by iterating over all items, and because if this, it can be slow for large scenes.
    3. QRectF rect = scene.itemsBoundingRect();
    4. scene.setSceneRect(rect);
    To copy to clipboard, switch view to plain text mode 

    Put this code in a slot connected to QGraphicsScene::changed() signal. That should appear as automatic.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    aliks-os (2nd November 2016)

  4. #3
    Join Date
    May 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to make the QGraphicsScene resize automaticly

    Hi, I have the same issue - if anyone could answer, that would be swell.
    Thanks

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,010
    Thanks
    233
    Thanked 636 Times in 626 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: how to make the QGraphicsScene resize automaticly

    Someone -did- answer: Santosh Reddy, in 2013. So if his code didn't solve -your- issue, then you don't have the same issue.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 0
    Last Post: 8th June 2012, 13:27
  2. Replies: 1
    Last Post: 24th March 2011, 04:29
  3. How to resize a QGraphicsScene to a QGraphicsView?
    By CassioTC in forum Qt Programming
    Replies: 2
    Last Post: 22nd March 2011, 09:03
  4. QGraphicsScene / QGraphicsView speed after resize
    By themolecule in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2007, 23:46
  5. How can I make size of QGraphicsScene smaller?
    By troorl_ua in forum Qt Programming
    Replies: 6
    Last Post: 21st April 2007, 07:56

Tags for this Thread

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.