Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how do i perform autoscroll in QTablewidget ? so it'll scroll down to bottom with a constant speed



  • so i've been struggling to do such, i've tried line such as scrolltobottom, autoscroll etc but it constantly go to the bottom without slowly descending.
    im using QT 5.11.2 version
    im still new using QT thanks



  • 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.



  • yea exactly like that, im gonna try that thanks



  • just to make it clear i want the table scroll down as its own just like a movie credit

    0_1553064512551_67bacff8-99ac-47dc-89f4-32d5c2bec977-image.png



  • This post is deleted!

  • Lifetime Qt Champion

    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);
    }
    

    alt text



  • 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();
    }
    

  • Lifetime Qt Champion

    @VRonin
    That actually runs nicer :)
    alt text



  • @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
    


  • @hskoglund so i need to to write thoose line again in order to make it loop?
    and it will lopp as much as i write it or something like that?



  • 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();
    }
    


  • @VRonin WOW YOURE A GOD!!! THNX ALOTT!!!


Log in to reply