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
Bookmarks