how to use QScroller::grabGesture(ui->scrollArea , QScroller::LeftMouseButtonGesture) in one or more scrollarea ?
-
how to use QScroller::grabGesture(ui->scrollArea , QScroller::LeftMouseButtonGesture) in one or more scrollarea ?
-
Hi
void MainWindow::SetupScroller() { QScroller::grabGesture(ui->scrollArea->viewport(), QScroller::LeftMouseButtonGesture); QVariant OvershootPolicy = QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff); QScrollerProperties ScrollerProperties = QScroller::scroller(ui->scrollArea->viewport())->scrollerProperties(); ScrollerProperties.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, OvershootPolicy); ScrollerProperties.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, OvershootPolicy); QScroller::scroller(ui->scrollArea->viewport())->setScrollerProperties(ScrollerProperties); ]Notice we use ui->scrollArea->viewport() as that the actual widget that is clicked on and not the scrollArea directly.
Also you might want to set Minimum Height/width for the view port as not having it being fit to the scrollArea if your use case is to have a scrollable
area that is smaller than area for the scrollArea.
-
Hi
void MainWindow::SetupScroller() { QScroller::grabGesture(ui->scrollArea->viewport(), QScroller::LeftMouseButtonGesture); QVariant OvershootPolicy = QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff); QScrollerProperties ScrollerProperties = QScroller::scroller(ui->scrollArea->viewport())->scrollerProperties(); ScrollerProperties.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, OvershootPolicy); ScrollerProperties.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, OvershootPolicy); QScroller::scroller(ui->scrollArea->viewport())->setScrollerProperties(ScrollerProperties); ]Notice we use ui->scrollArea->viewport() as that the actual widget that is clicked on and not the scrollArea directly.
Also you might want to set Minimum Height/width for the view port as not having it being fit to the scrollArea if your use case is to have a scrollable
area that is smaller than area for the scrollArea.
@mrjj ok, but this is used for only one scroll area for me. I want to use one or more scrollarea'a it is possible?
-
@mrjj ok, but this is used for only one scroll area for me. I want to use one or more scrollarea'a it is possible?
Yes just setup both Scrollareas
They won't scroll in sync if that is what you mean but both can scrollvoid MainWindow::SetupScroller(QScrollArea *area) { QScroller::grabGesture(area->viewport(), QScroller::LeftMouseButtonGesture); QVariant OvershootPolicy = QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff); QScrollerProperties ScrollerProperties = QScroller::scroller(area->viewport())->scrollerProperties(); ScrollerProperties.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, OvershootPolicy); ScrollerProperties.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, OvershootPolicy); QScroller::scroller(area->viewport())->setScrollerProperties(ScrollerProperties); } .... SetupScroller(ui->scrollArea3); SetupScroller(ui->scrollArea_2);