主要使用QTableView和QTableWidget中的三个函数实现

QTableView::verticalScrollBar()->setSliderPosition();  //设置当前滑动条的位置

QTableView::verticalScrollBar()->maximum();             //滑动条能移动的最大位置

QTableView::verticalScrollBar()->value();                   //获得当前滑动条的位置

 

 

  1. static int nCurScroller=0; //翻页时的当时滑动条位置
  2. static int pageValue = 10; // 一页显示条数
  3. void SplayHisForm::createHisForm()
  4. {
  5.                 …….
  6.     hisTableWidget = new QTableWidget;
  7.     hisTableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
  8.     hisTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
  9.             …….
  10. }
  11. /***下一页***/
  12. void SplayHisForm::nextPageHis()
  13. {
  14.     int maxValue = hisTableWidget->verticalScrollBar()->maximum(); // 当前SCROLLER最大显示值25
  15.     nCurScroller = hisTableWidget->verticalScrollBar()->value(); //获得当前scroller值
  16.     if(nCurScroller<maxValue)
  17.         hisTableWidget->verticalScrollBar()->setSliderPosition(pageValue+nCurScroller);
  18.     else
  19.         hisTableWidget->verticalScrollBar()->setSliderPosition(0);
  20. }
  21. /***上一页***/
  22. void SplayHisForm::prePageHis()
  23. {
  24.     int maxValue = hisTableWidget->verticalScrollBar()->maximum(); // 当前SCROLLER最大显示值25
  25.     nCurScroller = hisTableWidget->verticalScrollBar()->value();
  26.     if(nCurScroller>0)
  27.         hisTableWidget->verticalScrollBar()->setSliderPosition(nCurScroller-pageValue);
  28.     else
  29.         hisTableWidget->verticalScrollBar()->setSliderPosition(maxValue);
  30. }