如何使QtableView在向上和向下滚动方面可拖动。没有改变它的立场。就像在pdf阅读器中使用手动工具滚动页面一样。
答案 0 :(得分:0)
QScroller
类可以为任何滚动小部件或图形项启用动态滚动。
QScroller *scroller = QScroller::scroller(ui->tableView);
ui->tableView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
ui->tableViews->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
您可能希望禁用滚动条的过冲策略...
QScrollerProperties properties = QScroller::scroller(scroller)->scrollerProperties();
QVariant overshootPolicy = QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff);
properties.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, overshootPolicy);
scroller->setScrollerProperties(properties);
properties.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, overshootPolicy);
scroller->setScrollerProperties(properties);
//Scrolling Gesture
scroller->grabGesture(ui->tableView,QScroller::LeftMouseButtonGesture);
您可以将LeftMouseButtonGesture
替换为TouchGesture
用于触摸屏。