Results 1 to 6 of 6

Thread: How to achieve showAll ?

  1. #1
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default How to achieve showAll ?

    I'm doing an app based completely on GraphicsView. I need to implement a feature - showAll which on enabling should scale view such that all items are visible (criteria being scale factor should be as high as possible).
    My initial approach is this

    Qt Code:
    1. void SchematicView::showAll()
    2. {
    3. QRectF intersect;
    4. QList<QGraphicsItem*> _items = items();
    5. if ( !_items.isEmpty() ) {
    6. intersect = _items.first()->sceneBoundingRect();
    7. foreach( QGraphicsItem* it, _items ) {
    8. intersect |= it->sceneBoundingRect();
    9. }
    10. intersect.adjust( -10, -10, 10, 10);
    11. fitInView( intersect, Qt::KeepAspectRatio );
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    But somehow this method doesn't show all items. Some items are half shown . Can anyone help me ?
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  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: How to achieve showAll ?

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

  3. #3
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to achieve showAll ?

    Quote Originally Posted by wysota View Post
    Qt Code:
    1. fitInView(scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
    To copy to clipboard, switch view to plain text mode 
    Thanks for the answer. But scene()->itemsBoundingRect() does the same thing I'm doing now (OR'ing sceneBoundingRects). Unfortunately I still experience above said problems.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  4. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to achieve showAll ?

    Problem solved!!!

    The problem was with the size of scene rect. The scene rect was smaller than the viewport rect. After setting this right, it works without any problem.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  5. #5
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to achieve showAll ?

    what exactly did you do? you made the scene size equal or greater than the view size?
    Image Analysis Development Framework Using Qt (IADFUQ)

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to achieve showAll ?

    Equal. Setting it larger will cause the view to add scrollbars.

  7. The following user says thank you to marcel for this useful post:

    sincnarf (19th October 2007)

Similar Threads

  1. failing to achieve desired size of a BitField structure
    By nass in forum General Programming
    Replies: 8
    Last Post: 13th February 2007, 14:29

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.