PDA

View Full Version : ensureVisible() in QScrollArea. Problem with scrolling



AlGaN
7th October 2006, 00:17
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:



MainWindow::MainWindow()
{
scrollArea = new QScrollArea();
viewer = new QSvgViewer(scrollArea); // set scroll area to parent
scrollArea->setWidget(viewer);
...
setCentralWidget(scrollArea);
viewer->setFixedSize(6000, 4800); // widget has fixed size
viewer->resize(6000, 4800); // initial size scroll map widget
}


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:



void MainWindow::updatePos(int x, int y)
{
...
scrollArea->setFocus();
scrollArea->ensureVisible( x, y, scrollArea->width()/2, scrollArea->height()/2 );
...
}



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

jpn
7th October 2006, 12:25
I couldn't find anything in the Task Tracker or change logs, but one starting point could be to test with a more recent version of Qt. The release cycle of Qt is quite fast, 4.1.0 was released almost a year ago (Dec 2005 I think).. Could you provide a minimal compilable example reproducing the problem? Maybe someone could test it with a newer Qt to see if the problem still persists.

AlGaN
8th October 2006, 21:14
Hi jpn,

thanks for your hint with newer versions of Qt. I compiled with Qt 4.2.0 yesterday and the scrolling bug of ensureVisible() seems to have been gone :) . One should always use the latest version. Sorry for not provinding compilable example, my code base is a big chunk and I would have to strip it down to bare minimum to make things clear (I'm fighting with QThreads at the moment, so my code is no masterpiece up to now... :confused: )

Anyways thanks for reply & Regards
AlGaN