how do i perform autoscroll in QTablewidget ? so it'll scroll down to bottom with a constant speed
-
So is what you are asking, how to move down through a scrolled view one line at a time like the credits on a movie? You might try something like the QScroller class in combination with a QTimer to control the pixel movement speed. Just thinking out loud here.
-
Hi
Fast test
i have
ui->listWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
on.void MainWindow::on_pushButton_released(){ auto timer = new QTimer(this); connect(timer, &QTimer::timeout, this, [this](){ auto bar = ui->listWidget->verticalScrollBar(); bar->setValue( bar->value() + 1 ); }); timer->start(100); }
-
What about https://doc.qt.io/qt-5/qpropertyanimation.html ?
void MainWindow::on_pushButton_released(){ auto anim = new QPropertyAnimation(ui->listWidget->verticalScrollBar(),"value",this); anim ->setDuration(10000); anim->setStartValue(ui->listWidget->verticalScrollBar()->value()); anim->setEndValue(ui->listWidget->verticalScrollBar()->maximum()); connect(anim,&QAbstractAnimation::finished,anim,&QObject::deleteLater); anim->start(); }
-
@VRonin @mrjj WOW THANKS THATS EXACTLY LIKE I NEEDED THANKS A LOTT!!
oh yea and one more thing i've tried to make it loopin ands make it scroll to the top again by puttin theese lines after the anim->start();
if (tableWidget->verticalScrollBar()->maximum())
{
tableWidget->verticalScrollBar()->setSliderPosition(tableWidget->verticalScrollBar()->minimum());}
but it wont loopin am i wrong to put that there? -
Hi, when the animation stops at the bottom it's deleted, so if you want to loop it, you need to create/new up another one by doing all the steps again:
auto anim = new QPropertyAnimation(ui->listWidget->verticalScrollBar(),"value",this); anim ->setDuration(10000); ... etc etc
-
scroll to the top with animation:
void MainWindow::on_pushButton_released(){ auto anim = new QPropertyAnimation(ui->listWidget->verticalScrollBar(),"value",this); anim ->setDuration(10000); anim->setStartValue(ui->listWidget->verticalScrollBar()->value()); anim->setEndValue(ui->listWidget->verticalScrollBar()->maximum()); bool* once =new bool(true); connect(anim,&QAbstractAnimation::finished,[anim,this,once]()->void{ if(!once) return; *once=false; anim->setStartValue(ui->listWidget->verticalScrollBar()->value()); anim->setEndValue(ui->listWidget->verticalScrollBar()->minimum()); connect(anim,&QAbstractAnimation::finished,anim,&QObject::deleteLater); connect(anim,&QAbstractAnimation::finished,anim,[once](){delete once;}); anim->start(); }); anim->start(); }
Scroll to the top immediately
void MainWindow::on_pushButton_released(){ auto anim = new QPropertyAnimation(ui->listWidget->verticalScrollBar(),"value",this); anim ->setDuration(10000); anim->setStartValue(ui->listWidget->verticalScrollBar()->value()); anim->setEndValue(ui->listWidget->verticalScrollBar()->maximum()); connect(anim,&QAbstractAnimation::finished, ui->listWidget->verticalScrollBar(),std::bind(&QScrollBar::setValue,ui->listWidget->verticalScrollBar(),ui->listWidget->verticalScrollBar()->minimum())); connect(anim,&QAbstractAnimation::finished,anim,&QObject::deleteLater); anim->start(); }