Results 1 to 7 of 7

Thread: QGraphicsScene & QGraphicsView help please

  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsScene & QGraphicsView help please

    Hi!

    I have an application where the user can draw any diagram. The diagram area is resizeable. For this I am reimplemented QGraphicsScene and QGraphicsView classes.

    1. sceneRect is initially lets sat set to (0, 0, 100, 100) which is smaller than the viewport of QGraphicsView.
    2. I draw a resize handler in the function drawForeground in the sceneRect. It appears fine at the right and the bottom edges of the scene in the viewport.
    3. I have reimplemented the mouseMoveEvent, mousePressEvent and mouseReleaseEvent of QGraphicsScene such that when the mouse is pressed on the resize handler and dragged the scene is resized by calling setSceneRect.

    Now, when the size of the sceneRect becomes more than viewport scrollbar appears but they do not drag along and therefore the size cannot be resized smoothly.

    Also, when the scroll bars appear and if we try to reduce the size of the sceneRect using the handlers at the edges, the scrollbars disappear immediately.

    Can you someone please help me impelement this the right way?

    Thanks,

  2. #2
    Join Date
    May 2008
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene & QGraphicsView help please

    you can set the size of the scene rectangle to the QGraphicsView's maximum viewport size.

    in your QGraphicsView's resizeEvent, you can set the sceneRect to the maximum viewport size of the QGraphicsView by using QAbstractScrollArea::maximumViewportSize.

    this way you will have the same sized scene and view and no scrollbar will be seen.

    I hope this was what you need..

  3. #3
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene & QGraphicsView help please

    Quote Originally Posted by alisami View Post
    this way you will have the same sized scene and view and no scrollbar will be seen.

    I hope this was what you need..
    I think you misunderstood my question. Its not that I don't want scrollbars to appear. Infact, I do want scrollbars to appears. The problem is that they are not behaving correctly.

    When I resize sceneRect dynamically using the resize handler everything is fine till the the size of the sceneRect is smaller than the viewable area of the graphics view. Once is grows bigger than that, the scroll bars appear but then they do not scroll along and hence the size cannot be increased further using the resize handler.

    Also, when the sceneRect size is greater than the viewable area and if we try to reduce the size, then the scrollbars disappear immediately.

    I hope its clearer this time.

    Thanks,

  4. #4
    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: QGraphicsScene & QGraphicsView help please

    i am not sure but ..
    Qt Code:
    1. fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
    To copy to clipboard, switch view to plain text mode 

    which aspect ratio u are using ...? may be this one creates problem ...
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    May 2008
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene & QGraphicsView help please

    munna, can you provide an example code which generates the error?

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene & QGraphicsView help please

    Never mind, I fixed this problem.

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene & QGraphicsView help please

    @munna would be nice if you post the solutions for the benefit of other users that face a similar problem in the future.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 20:50
  2. Replies: 0
    Last Post: 5th March 2009, 06:54
  3. QGraphicsView and QGraphicsScene
    By alisami in forum Qt Programming
    Replies: 8
    Last Post: 4th December 2008, 10:10
  4. QGraphicsScene and QGraphicsView
    By sabeesh in forum Qt Programming
    Replies: 7
    Last Post: 1st August 2007, 06:59
  5. QGraphicsScene and QGraphicsView
    By rossd in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2007, 14:43

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.