Unlogical running of scrollTo() in QTableView
-
I have a playlist table inherited from QTableView that periodically changes of line. It has also an autoScroll method that tries to scroll automatically to next line if it is not visible in the QTableView::vierport().
The problem is that some times the current playing line is located in a specific row i.e. 500 and I want to scrollTo() the 2000. I have debugged Qt and I have seen that it stores the new value but does not scroll due to the new viewport doesn't intersects with the old. The reason seems that it is done for performance reasons as it is explained in a comment at QAbstractItemView::update().
Is there any way to force the line scroll change?
-
QAbstractItemView::update() just doesn't repaint rects that do not intersect with the viewport's rect. Since scrollTo() adjusts the scrollbars beforehand the repaint should happen in all cases (when scrollTo() is called).
The problem is that scrollTo() is implemented in such a way that it does not update the scrollbars when the index' visualRect is already inside the viewport.
A dirty hack would be to call "QAbstractItemView::scrollToTop()":http://qt-project.org/doc/qt-4.8/qabstractitemview.html#scrollToTop first and then call scrollTo().
If that doesn't lead to a desired result you have to subclass QTableView class and reimplement scrollTo() (since it's virtual). -
Finally, what I have done is to calculate the row range of the row that I want to visualize and in this case, force the call to the method again. Is not elegant, but in this case it runs... I think that the next step is to reimplement scrollTo() since my table is already subclassed from QTableView.
Could this method be considered a bug or could be purposed to be changed?