PDA

View Full Version : QTableWidget::verticalScrollBar()->maximum() is always 0



AnthonyL
24th July 2016, 17:56
In my application there are 3 tables. I update them in callback from QProcess with listing from the external program – after calling rowCount(0), i.e. after first clearing the tables. First two tables have vertical QScrollBar::maximum() automatically updated so that I know what is the QScrollBar's maximum setValue() argument. However, not knowing why, third table has maximum() stuck at 0. What can be the cause? The code is the same for the 3 tables, and in general, maximum() should be updated as I call insertRow(), this should be an independent action. Why it isn't updated in the single table?

Currently I solve this by calling setMaximum() before setValue() – I set the maximum to a large number, two times larger than number of rows in QTableWidget.

d_stranz
24th July 2016, 20:39
Why it isn't updated in the single table?

I'm guessing you have a bug in your code. But since you haven't shown us any code, that's all it is, a guess. I could guess something else, but I think "a bug" is a good guess, so I'll stick with it.

AnthonyL
25th July 2016, 08:46
It's hard to provide small piece of code but I can first provide the whole project. Few helper conclusions:

Scroll bar positions are remembered in rememberScrollBars();
First two QTableWidgets (ui->tableWidget, ui->tableWidget_2) are being filled with insertLZCSDTableRow()
The third (problematic) QTableWidget is being filled with insertLZSDETableRow() (so LZSDE, not LZCSD)
The QProcess-triggered callbacks that provide data for the tables are: handle_zkiresize_list() for tableWidget&tableWidget_2, handle_zkiresize_consistent() for tableWidget_3
Vertical scroll bar position is restored (comment "RESTORE SCROLL", 3 times in code) via e.g. ui->tableWidget_3->verticalScrollBar()->setValue(...)
I now always call setMaximum() to a large value (two times the expected maximum) before calling setValue(), and this helps


Who knows, maybe someone would like to build this project. CMake can build everything, but there are also .pro files, and one could just fix libraries paths in it. I guess building own libgit2 might not be a great idea, but it's fixable by just changing library reference to an external one, in manager.pro file. To run the project one needs psprint/zkl (https://github.com/psprint/zkl) github repository placed at ~/.zekyll/repos/gh---psprint---zkl---master, and backend "zekyll" (https://github.com/psprint/zekyll) placed at ~/.zekyll/zekyll

The source:

remembering of scroll bars' positions: https://github.com/psprint/QtZekyllManager/blob/39ca5680148edd884713dd508b890c9b912b6598/manager/mainwindow.cpp#L697-L702
rememberScrollBars() code https://github.com/psprint/QtZekyllManager/blob/39ca5680148edd884713dd508b890c9b912b6598/manager/mainwindow.cpp#L1370-L1376

filling of tableWidget_3 (the problematic one): https://github.com/psprint/QtZekyllManager/blob/39ca5680148edd884713dd508b890c9b912b6598/manager/mainwindow.cpp#L250-L261
filling of tableWidget and tableWidget_2: https://github.com/psprint/QtZekyllManager/blob/39ca5680148edd884713dd508b890c9b912b6598/manager/mainwindow.cpp#L155
the setValue() call, which is problematic (maximum() == 0) when there is no preceding setMaximum() call: https://github.com/psprint/QtZekyllManager/blob/39ca5680148edd884713dd508b890c9b912b6598/manager/mainwindow.cpp#L280

anda_skoa
25th July 2016, 09:42
Overriding the maximum of a table view's scrollbar doesn't sound like a very good idea.
That value is usually determined by the table's data, i.e. how many rows it has an how high these rows are.

Cheers,
_

AnthonyL
25th July 2016, 17:19
Overriding the maximum of a table view's scrollbar doesn't sound like a very good idea.
That value is usually determined by the table's data, i.e. how many rows it has an how high these rows are.

Cheers,
_

Yeah, but in my case, 1 out of 3 QTableWidgets doesn't have maximum() of verticalScrollBar updated. That's the point, the value is stuck at 0 despite insertRow() calls