Issue
I'm using a QTableView in Qt (PyQt4, actually). The vertical scrollbar acts very weird, different than how a QTableWidget scrollbar or any other scrollbar acts. I have a large table, with thousands of rows. The handle (the clickable/draggable portion) of the vertical scrollbar always starts out larger (taller) than it should. When I use my scroll wheel to scroll down the table to the point where the handle is at about the 90% position of the scrollbar (even though I'm only say 30% through the table), the handle suddenly moves back up to say the 70% position of the scrollbar and shrinks a bit in size. As I traverse the rest of the table, the handle repeats this behavior, getting a little smaller each time and jumping back up the scrollbar to about the 70% position every time the handle gets to the bottom of the scrollbar.
Note that this strange behavior only happens when my table is pretty long (say at least 500 rows).
I appreciate that this is an interesting mechanic and makes some sense, but it must be optional. Is there some way to disable it and get a scrollbar handle which behaves normally in a long table?
All I'm doing with the QTableView is creating it and setting its model to a QSqlQueryModel which uses a basic SQL query to a database.
Solution
The model only fetches the amount of data necessary for the viewport at the start. Doing this at the start fixes it:
model = QSqlQueryModel()
model.setQuery("select some stuff", db)
while model.canFetchMore():
model.fetchMore()
tableView.setModel(model)
Answered By - Pat Flegit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.