Results 1 to 5 of 5

Thread: How to find position of QGraphicsView within QgraphicsScene

  1. #1
    Join Date
    Oct 2009
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to find position of QGraphicsView within QgraphicsScene

    Just a quick question. I'm sure there's a solution out there, but I'm apparently not readily finding the appropriate function for QGraphicsView. See, my scene is much larger than the qgraphicsview (What I see of the scene in the window, as far as my understanding goes) and the user has the choice to scroll around the scene. Is it possible to find out exactly where the view is located in the scene as the user scrolls around and how? I basically need to know the scene coordinates of the view in the top left corner and bottom right corner.

    Also, does anyone know how to disable the scroll bars but still have a QGraphicsScene larger than the QGraphicsView? Or... is it possible to load images that are positioned outside the scene? I basically want to preload images before they come into the view, but the user shouldn't be able to scroll into the "preloading images" area on the outside of the view.

    EDIT:

    I found that one could find the scene coordinates of a view using QGraphicsView's mapToScene(), but now I need to find where a QGraphicItem's position is in the view. How would one do that?

    Do I need to get the item's scene, and then I can get the view using one of the scene's methods, and then use the above method? What steps does that take? It doesn't seem like I can get an item's scene or view but I may just be a n00b.
    Last edited by swbluto; 28th October 2009 at 20:04.

  2. #2
    Join Date
    Oct 2009
    Posts
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to find position of QGraphicsView within QgraphicsScene

    It doesn't seem like I can edit my previous post?

    Anyways, I found that I could find graphicItems position in the view by finding out what the view's scene coordinates are and comparing it to the graphicItem's coordinate functions which are scene coordinates.

    To get the graphicsView from the graphicItem class, though, I had to call scene() and then I had to call views(), I then had to call first() to get the only view from the views list that I assigned to the scene. From there, I used mapToScene(0,0) to get the QGraphicsView's top left coordinate and the right and bottom was calculated using width() and height().

  3. #3
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: How to find position of QGraphicsView within QgraphicsScene

    For me, it sounds strange what you are asking for. You should never bother about things in the view because you can have more than one view on a single scene. If you do calculations based on the view, you will have to do it again for every view. You get proper translated mouse events in the scene. Do all your business in the scene. Also preloading of images into the graphicsscene should not be necessary, at least not something hacky like adding them to the scene but outside of the visible rectangle. Loading the QPixmap to some variable should be enough.
    It's nice to be important but it's more important to be nice.

  4. #4
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: How to find position of QGraphicsView within QgraphicsScene

    I think that's what he wants to do. Prereload an image during startup and showing it when it's inside the view, so he needs the view's position to know when to create them.

    By the way, did you find, swbluto, the way to disable the scroll bars?

  5. #5
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: How to find position of QGraphicsView within QgraphicsScene

    Yes I understand that he wants to do that but for me it does not make sense to use that hacky solution to archive that result. Dont do that. Dont try to do hacky things with Qt.




    To disable scroll bars, set horizontalScrollBarPolicy and verticalScrollBarPolicy.
    It's nice to be important but it's more important to be nice.

Similar Threads

  1. Replies: 0
    Last Post: 29th September 2009, 02:28
  2. Qt and VC++ instalation problem
    By gui.br in forum Installation and Deployment
    Replies: 6
    Last Post: 21st July 2009, 07:13
  3. Replies: 1
    Last Post: 11th June 2009, 05:49
  4. Replies: 0
    Last Post: 5th March 2009, 06:54
  5. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06

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.