QTableWidget smooth scrolling

Foreword: This is the first time I post a technical post on the Internet. In order to realize this function, I searched for a long time on the Internet, but there is no specific implementation. When I realized this function with a few lines of code, I was very moved. I hereby share it. , I hope everyone avoids stepping on the pit, if it helps everyone, I hope everyone will like it to prove that my post is meaningful

The default scrolling method of QTableWidget:

To achieve the completed effect:

Code: There is no subclassing QTableWidget here, you can choose subclassing, and this example does not replace item with widget interface, you can also replace it, anyway, the final effect can be achieved with these three lines of code, many online are just set to pixels Move, but after setting to pixel movement, just dragging the scroll bar is useful, the scroll wheel is useless

    ui->tableWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); //设置为像素移动
    QScrollBar * a = ui->tableWidget->verticalScrollBar(); //获取到tablewidget的滚动条
    a->setSingleStep(5); //设置单步,值越小,下滑越慢

Guess you like

Origin blog.csdn.net/qq_25704799/article/details/120375426