I would like to scroll my QScrollbar
to center; I thought it was easy, but
QScrollBar *bar = ui->scrollArea->horizontalScrollBar();
bar->setValue(bar->maximum()/2);
bar->update();
ui->scrollArea->update();
doesn't do the job. What goes wrong?
I would like to scroll my QScrollbar
to center; I thought it was easy, but
QScrollBar *bar = ui->scrollArea->horizontalScrollBar();
bar->setValue(bar->maximum()/2);
bar->update();
ui->scrollArea->update();
doesn't do the job. What goes wrong?
In Qt's documentation the actual document length is defined by
document length = maximum() - minimum() + pageStep() (See QScrollBar Class Reference)
So try replacing
int center = (min+max)/2;
with
int center = (max+min+bar->pagestep())/2;
A QScrollBar
has a minimum, too. So to center a scrollbar:
int max = bar->maximum();
int min = bar->minimum();
int center = ( min + max ) / 2;
bar->setValue( center );