Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    6
    13
    1254
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Redho B N last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Kent-Dorfman
        Kent-Dorfman last edited by

        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.

        1 Reply Last reply Reply Quote 1
        • R
          Redho B N last edited by

          yea exactly like that, im gonna try that thanks

          1 Reply Last reply Reply Quote 0
          • R
            Redho B N last edited by

            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

            1 Reply Last reply Reply Quote 0
            • F
              farhanrbn last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion last edited by

                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

                1 Reply Last reply Reply Quote 4
                • VRonin
                  VRonin last edited by

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

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  mrjj 1 Reply Last reply Reply Quote 5
                  • mrjj
                    mrjj Lifetime Qt Champion @VRonin last edited by

                    @VRonin
                    That actually runs nicer :)
                    alt text

                    1 Reply Last reply Reply Quote 1
                    • R
                      Redho B N last edited by Redho B N

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

                      1 Reply Last reply Reply Quote 0
                      • hskoglund
                        hskoglund last edited by

                        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
                        
                        R 1 Reply Last reply Reply Quote 1
                        • R
                          Redho B N @hskoglund last edited by

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

                          1 Reply Last reply Reply Quote 0
                          • VRonin
                            VRonin last edited by VRonin

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

                            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                            ~Napoleon Bonaparte

                            On a crusade to banish setIndexWidget() from the holy land of Qt

                            R 1 Reply Last reply Reply Quote 4
                            • R
                              Redho B N @VRonin last edited by

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

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post