Results 1 to 4 of 4

Thread: increase scenerect with add item in qgraphicsview

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default increase scenerect with add item in qgraphicsview

    hi friends,experts,

    im having a scene where items will be added continuously and out of specific sceneRect. items can be added infinite .

    ex: if i set the scene rect as (0, 0, 5000, 5000) there is a chance that an item can be added say pos (5010, 5010) so i cant able to define the scene rect .
    im implementing panning on graphicsview . so i need the scene rect to restrict within the items added . the item can be increased and the scene rect has to increase proposition to it. if i set 32000x32000 even if no items has been added. it wil lshow lots of empty spaces

    i cant use scene->setSceneRect(scene->itemsBoundingRect()); because initially there wont be any item and i have to drop the item to scene rect.

    so i need to specify initilaly some sceneRect like viewport->rect() of graphicsview. then i have to increase it when ever any items added .

    so how i can increase the sceneRect when the items keep on adding and the view increases its scroll area.

    thanks in advance.
    "Behind every great fortune lies a crime" - Balzac

  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: increase scenerect with add item in qgraphicsview

    Any specific reason for setting the scene rect?
    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. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: increase scenerect with add item in qgraphicsview

    Quote Originally Posted by Santosh Reddy View Post
    Any specific reason for setting the scene rect?
    thanks for the reply

    Panning and zooming .
    the items can be added one after another like a tree view .
    so some branch item can be shown away from the viewport.contentsRect()

    in that case i have to pan the view . like http://www.qtcentre.org/wiki/index.p...ng_and_Zooming

    but in that example the scene rect is defined which is not in my case.

    my current implementation is

    when an item is added

    Qt Code:
    1. QGraphicsView *view = this->views().at(0);
    2. QRectF viewRect = view->contentsRect();
    3. QRectF itemsBounds = this->itemsBoundingRect();
    4.  
    5.  
    6.  
    7. if(itemsBounds.width() >= sceneRect().width())
    8. {
    9. this->setSceneRect(itemsBoundingRect());
    10. }else
    11. this->setSceneRect(view->contentsRect());
    12.  
    13. if(itemsBounds.height() >= sceneRect().height())
    14. {
    15. this->setSceneRect(itemsBoundingRect());
    16. }else
    17. this->setSceneRect(view->contentsRect());
    To copy to clipboard, switch view to plain text mode 


    but i dont think it is a correct way .

    thanks
    "Behind every great fortune lies a crime" - Balzac

  4. #4
    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: increase scenerect with add item in qgraphicsview

    Don't set the scene rect at all, it should work by itself. Just keep adding the items.
    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.

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

    wagmare (10th March 2015)

Similar Threads

  1. Replies: 0
    Last Post: 13th February 2012, 02:52
  2. Replies: 1
    Last Post: 9th February 2011, 23:06
  3. How to increase size of QGraphicsView Dynamically
    By Kingofhearts_sri in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2009, 08:54
  4. MDI display Item in QGraphicsView
    By wisconxing in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2008, 00:11
  5. QGraphicsView and item focus
    By Micawber in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2007, 20:36

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.