主要使用QTableView和QTableWidget中的三个函数实现
QTableView::verticalScrollBar()->setSliderPosition(); //设置当前滑动条的位置
QTableView::verticalScrollBar()->maximum(); //滑动条能移动的最大位置
QTableView::verticalScrollBar()->value(); //获得当前滑动条的位置
- static int nCurScroller=0; //翻页时的当时滑动条位置
- static int pageValue = 10; // 一页显示条数
- void SplayHisForm::createHisForm()
- {
- …….
- hisTableWidget = new QTableWidget;
-
hisTableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
-
hisTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
-
…….
- }
- /***下一页***/
- void SplayHisForm::nextPageHis()
- {
- int maxValue = hisTableWidget->verticalScrollBar()->maximum(); // 当前SCROLLER最大显示值25
- nCurScroller = hisTableWidget->verticalScrollBar()->value(); //获得当前scroller值
-
if(nCurScroller<maxValue)
-
hisTableWidget->verticalScrollBar()->setSliderPosition(pageValue+nCurScroller);
-
else
-
hisTableWidget->verticalScrollBar()->setSliderPosition(0);
- }
- /***上一页***/
- void SplayHisForm::prePageHis()
- {
- int maxValue = hisTableWidget->verticalScrollBar()->maximum(); // 当前SCROLLER最大显示值25
-
nCurScroller
= hisTableWidget->verticalScrollBar()->value();
-
if(nCurScroller>0)
-
hisTableWidget->verticalScrollBar()->setSliderPosition(nCurScroller-pageValue);
-
else
-
hisTableWidget->verticalScrollBar()->setSliderPosition(maxValue);
- }