Results 1 to 6 of 6

Thread: QGraphicsScene Scrollbar resizing

  1. #1
    Join Date
    Jul 2009
    Location
    Orange County California
    Posts
    8
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsScene Scrollbar resizing

    I have a QGraphicsView class with a QGraphicsScene.

    In the scene I add items, much like in a ListView. When the number of items exceed what will fit in the view, scrollbars appear much like they should. Behavior is exactly what I want at this point.

    When items are removed from the scene so that all of the remaining items are visible in the list, the scrollbars are still there.

    Shouldn't the scrollbars disappear when not needed? I can use the scrollbars to scroll to the bottom of the scene (where the scene was previosly pupulated with items), but there are no items at the bottom anymore because they were previously removed, so the scene should resize and the scrolbars disappear.

    Qt Code:
    1. for (int index = 0; i <= itemsInList(); index++)
    2. {
    3. m_scene->addItem( myItem[index]) ;
    4. }
    5.  
    6. for (int index = 0; i <= itemsInList(); index++)
    7. {
    8. if ( myItem[index]->isSelected() )
    9. {
    10. m_scene->removeItem( myItem[index] );
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene Scrollbar resizing

    The need of scrollbars of a QGraphicsView depends on QGraphicsScene::sceneRect. The sceneRect grows but never shrinks automatically. You have to adjust it manually, for example with:

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

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

    ikeurb (10th July 2009)

  4. #3
    Join Date
    Jul 2009
    Location
    Orange County California
    Posts
    8
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Talking Re: QGraphicsScene Scrollbar resizing

    Great! That was it. I knew it had to be something simple that I wasn't doing.

    THANKS!

  5. #4
    Join Date
    Jul 2009
    Location
    Orange County California
    Posts
    8
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QGraphicsScene Scrollbar resizing

    Aagh, now there is a new issue.

    The scene does resize correctly as items are added and removed to the scene. This is good.

    However, if ALL of the items are removed from the scene, the scrollbars then reappear.

    With the scene empty, there should not be any scrollbars.

    ???
    Last edited by ikeurb; 10th July 2009 at 21:18.

  6. The following user says thank you to ikeurb for this useful post:

    shentian (10th July 2009)

  7. #5
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene Scrollbar resizing

    Thanks, I never checked this case in my app, didn't work there either.

    I there are no items, QGraphicsScene::itemsBoundingRect returns the null QRectF. But QGraphicsScene::setSceneRect ignores the null QRectF. This should work:

    Qt Code:
    1. QRectF rect = m_scene->itemsBoundingRect();
    2. if (rect.isNull())
    3. {
    4. m_scene->setSceneRect(QRectF(0, 0, 1, 1));
    5. }
    6. else
    7. {
    8. m_scene->setSceneRect(rect);
    9. }
    To copy to clipboard, switch view to plain text mode 

  8. The following 2 users say thank you to shentian for this useful post:

    ikeurb (14th July 2009), JovianGhost (22nd March 2010)

  9. #6
    Join Date
    Jul 2009
    Location
    Orange County California
    Posts
    8
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene Scrollbar resizing

    That did the trick. Simple enough!

    Thanks again.

Similar Threads

  1. Replies: 0
    Last Post: 5th March 2009, 06:54
  2. QPixmap display on QGraphicsScene
    By febil in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2009, 09:27
  3. Treeview scrollbar not updating when inserting rows
    By Khal Drogo in forum Qt Programming
    Replies: 11
    Last Post: 29th November 2007, 13:13
  4. GraphicsView/GraphicsScene: scrollbar policy Qt::ScrollBarAsNeeded
    By Pieter from Belgium in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2007, 13:15
  5. about scrollbar style
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 13:34

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.