Hi,

sorry if this issue has been discussed before, search didn't find anything relevant...
I'm a very newbie with Qt and have problems with the function ensureVisible(int x, int y, int xmargin, int ymargin) method of QScrollArea class
Qt version: 4.1.0 both on Win/Linux

I have a MainWindow subclassed from QMainWindow that has a QScrollArea as its main widget. In this QScrollArea I set a viewer widget, which is subclassed from QWidget as this:

MainWindow class:

Qt Code:
  1. MainWindow::MainWindow()
  2. {
  3. scrollArea = new QScrollArea();
  4. viewer = new QSvgViewer(scrollArea); // set scroll area to parent
  5. scrollArea->setWidget(viewer);
  6. ...
  7. setCentralWidget(scrollArea);
  8. viewer->setFixedSize(6000, 4800); // widget has fixed size
  9. viewer->resize(6000, 4800); // initial size scroll map widget
  10. }
To copy to clipboard, switch view to plain text mode 

The widget's size is very large (6000x4800 px) in contrast to the QScrollArea, which has the size of the MainWindow's base class window. In one method of MainWindow class I want to center the QScrollArea's widget to a defined point of the widget:

Qt Code:
  1. void MainWindow::updatePos(int x, int y)
  2. {
  3. ...
  4. scrollArea->setFocus();
  5. scrollArea->ensureVisible( x, y, scrollArea->width()/2, scrollArea->height()/2 );
  6. ...
  7. }
To copy to clipboard, switch view to plain text mode 

In the above call I want to center the widget to the point (x,y) in the scroll area. Unfortunately the method ensureVisible() does not always function properly, sometimes the "center of focus" gets out of the viewport and one has to manually scroll it to see the "cursor" in my widget.
I have searched for bugs in Qt, but didn't find any...

I'd appreciate any hints & explanations of this class, because there is not much documentation with Qt in this class... If somebody could provide an example of proper use of ensureVisible() with Qt's QScrollArea or give another solution to the "center of focus" problem I would be very thankful.

Thx & Regards
AlGaN