Results 1 to 6 of 6

Thread: How to find out what physical pixels of an image in a QGraphicsItem are displayed

  1. #1
    Join Date
    Jan 2011
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to find out what physical pixels of an image in a QGraphicsItem are displayed

    lets say I have a QGraphicsView that is 50 x 50, and a QGraphicsItem that is 100x100.

    Obviously the whole image will not fit in the view at any given time.

    I can pan the QGraphicsItem around, scale it, etc etc in the window.

    Is there any way to derive which physical pixels of the original image are being displayed at any given time?

    For example - if I have panned all the way to the right, it might be the pixels 50-100 in the x direction, and 0-50 in the Y direction. If I have zoomed out some, it may be that ALL of the image is now in the viewer.

  2. #2
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: How to find out what physical pixels of an image in a QGraphicsItem are displayed

    (1) You can compute pixel metric. That is, in QGraphicsItem's local coordinates "1 pixel is x (qreal) long and y (qreal) tall" (I wonder if it's not as simple as 1=1.0)
    Then, according to your image dimensions (in pixels), you know that a QPointF given in item's coordinate match with a pixel in your image (apply pixel metric and cast it to QPoint).

    (2) Now, given QPoints in view's coordinate system (for instance its viewport corners), map it to the GraphicsItem local coordinate system and make (1). This should give you the corresponding image rect currently visible.

    (3) As you said, zooming out might make the image fully visible in the viewer (and maybe surrounded with 'empty' space); In this case mapping your viewport to GraphicsItem local coordinates will compute out-of-bounds pixel indices. But this is the idea

  3. #3
    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 find out what physical pixels of an image in a QGraphicsItem are displayed

    What do you need this information for?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jan 2011
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to find out what physical pixels of an image in a QGraphicsItem are displayed

    I am trying to basically show lat/long coordinates along with a map that is displayed. If you zoom in on the map, you are now viewing a smaller geographic region, zoom out, bigger region

  5. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to find out what physical pixels of an image in a QGraphicsItem are displayed

    Quote Originally Posted by dcole View Post
    I am trying to basically show lat/long coordinates along with a map that is displayed. If you zoom in on the map, you are now viewing a smaller geographic region, zoom out, bigger region
    Have a look at QGraphicsView.sceneRect().

  6. #6
    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 find out what physical pixels of an image in a QGraphicsItem are displayed

    Quote Originally Posted by dcole View Post
    I am trying to basically show lat/long coordinates along with a map that is displayed. If you zoom in on the map, you are now viewing a smaller geographic region, zoom out, bigger region
    Still I don't see what you need such an information for. Anyway:
    Qt Code:
    1. QRectF visibleRect = view->mapToScene(view->viewport()->rect());
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 9
    Last Post: 13th June 2012, 15:42
  2. QGraphicsItem mousePressEvent only on opaque pixels
    By jonks in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2010, 10:24
  3. image not displayed ...
    By sh123 in forum Qt Tools
    Replies: 4
    Last Post: 15th December 2008, 13:07
  4. no image displayed on QGraphicsView
    By sincnarf in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2007, 12:33
  5. JPEG Image isn't displayed!?
    By GodOfWar in forum Qt Programming
    Replies: 9
    Last Post: 16th April 2007, 15:01

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.