Results 1 to 2 of 2

Thread: QScrollArea relative viewport coordinates

  1. #1
    Join Date
    Apr 2006
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Post QScrollArea relative viewport coordinates

    I'm looking for a way to find the viewport coordinates relative to the Widget inside.
    So when we scroll to the bottom right corner I get something like 50,50,600,800

    The basic idea behind it is a previewpane for a picture viewer, and the part currently shown in the viewport should be marked (rectangle round it or something)

    I've tried some simple mapping options, and some own calculations based on the scrollbar value, but everything seems to start from 0,0 coordinates and return the viewport size. I am kinda stuck now


    getActiveImageFramePtr() returns currect selected widget in the MDI
    the widget extends QScrollArea

    double absXOffset = 0;
    double absYOffset = 0;

    //Determine relative and absolute offset which then can be used to offset the viewport rectangle, scale that to previewpane size and i should have the correct rectangle ?!?

    if( getActiveImageFramePtr()->horizontalScrollBar()->maximum() > 0 )
    {
    double relXOffset = getActiveImageFramePtr()->horizontalScrollBar()->value() / getActiveImageFramePtr()->horizontalScrollBar()->maximum();
    absXOffset = relXOffset * getActiveImageFramePtr()->getSizePicture( ).width();
    }

    if( getActiveImageFramePtr()->verticalScrollBar()->maximum() > 0 )
    {
    double relYOffset = getActiveImageFramePtr()->verticalScrollBar()->value() / getActiveImageFramePtr()->verticalScrollBar()->maximum();
    absYOffset = relYOffset * getActiveImageFramePtr()->getSizePicture( ).height();
    }

    rect.adjust(absXOffset, absYOffset, absXOffset, absYOffset )


    One of my other tests was mapping the label (inside the scrollarea, shows the picture) to the scrollarea, but that always returns 0,0, picture.width(), picture.height()

    getActiveImageFramePtr()->getLabel()->mapTo(getActiveImageFramePtr(),QPoint(0,0));
    QRect rect = getActiveImageFramePtr()->getLabel()->rect();


    Any help would be appreciated Thanks
    Last edited by kalanikta; 21st April 2006 at 11:17.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QScrollArea relative viewport coordinates

    Check this thread (especially posts 4-5).
    J-P Nurmi

Similar Threads

  1. Viewport and scene coordinates
    By aurelius in forum Newbie
    Replies: 2
    Last Post: 31st October 2008, 00:47

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.