PDA

View Full Version : QTableWidget - scrolling to bottom of the table



mkhoang
10th November 2008, 23:15
I'm having this problem with scrolling to the bottom of my QTableWidget.
I want the scroll bar to stay at the bottom as the table grows if the scroll bar is at the bottom to begin with.
But when I call scrollToBottom(), the scroll bar moves only to the beginning of the last row inserted which is not always necessarily the bottom of the table because sometimes the height of the last row inserted is really large, how can I make the scroll bar move all the way to the bottom and not scroll to the last row in the table?

here's my code:

int max_slider_pos = table->verticalScrollBar()->maximum();
bool move_slider_to_bottom = false;

if(table->verticalScrollBar()->sliderPosition() == max_slider_pos)
{
move_slider_to_bottom = true;
}

// insert new row here

table->resizeRowsToContents();

table->resizeColumnsToContents();

if(move_slider_to_bottom)
{
table->scrollToBottom();
}

Thanks for the help!

caduel
11th November 2008, 07:04
see QAbstractItemView::scrollToBottom()

mkhoang
11th November 2008, 14:16
I do use scrollToBottom, as I mentioned in my first post, but it doesn't work well for me because some of my row heights are pretty large

Ginsengelf
12th November 2008, 07:32
How about


table->verticalScrollBar()->setSliderPosition (table->verticalScrollBar()->maximum())

instead of scrollToBottom()?


Ginsengelf

mkhoang
12th November 2008, 17:21
yeah, i tried that too, ends up doing the same thing as scrollToBottom()