Results 1 to 4 of 4

Thread: How to get the visible rect of a QGraphicsView ?

  1. #1
    Join Date
    Oct 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X

    Default How to get the visible rect of a QGraphicsView ?

    Hi there,

    I want to retrieve the currently visible rectangle of a QGraphicsView (Qt 4), since by zooming in and scolling around that visible region is obviously changed and doesn't match the scene rect anymore (this is going to be used to simply visualize the currently visible region in some overview widget - like the similar function in Photoshop or other image editing programs).

    Is there any API method like QGraphicsView::fitInView which seems to be the opposite of what I'm trying to do? For instance, I know that there was QWidget::visibleRect() in Qt 3 but not in Qt 4. Maybe there is some replacement?

    Currently, I'm trying to manually calculate that visible rect by the scroll bar positions and the current scale factor - but not yet successfully.

    Thanks.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get the visible rect of a QGraphicsView ?

    Am not sure, but you can try QWidget::visibleRegion
    Also have a look at QAbstractScrollArea::viewportHope it helps

  3. #3
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get the visible rect of a QGraphicsView ?

    If you haven't rotated your scene/view
    Qt Code:
    1. QRectF scenerect = QRectF(mapToScene(0,0), mapToScene(width(), height()));
    To copy to clipboard, switch view to plain text mode 
    should work. Otherwise
    Qt Code:
    1. QPolygonF trapezoid = mapToScene (rect());
    To copy to clipboard, switch view to plain text mode 
    should return the trapezoid of the viewRect.

  4. #4
    Join Date
    Oct 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to get the visible rect of a QGraphicsView ?

    Hi,

    ok, after having a second thought, this was easy - thanks to your replies. I did somthing like this (let's suppose, we are in the "overviewing widget"):

    Qt Code:
    1. QMatrix const matrix = overviewedGraphViewWidget->matrix().inverted();
    2. QRect visibleRect = matrix.mapRect(overviewedWidget->viewport()->rect());
    3.  
    4. // when the viewport is scrolled, then the top left point of the visible rectangle needs to be moved
    5. // according to the scroll bar positions
    6. visibleRect.moveTopLeft(matrix.map(QPoint(overviewedWidget->horizontalScrollBar()->value(),
    7. overviewedWidget->verticalScrollBar()->value())));
    To copy to clipboard, switch view to plain text mode 

    Probably, I don't need to request the viewport, but can work with the overviewed widget itself.

    Greets.

Similar Threads

  1. How to set definite Scene Rect in QGraphicsView.
    By AmolShinde_8 in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2008, 16:18

Tags for this Thread

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.