How to catch event of scrolling inside QScrollArea ?
-
i want to add slot on 'scrolling' inside QScrollArea. if anybody know how to achieve this then let me know.
-
Hi
QAbstractScrollArea provides methods to access its scroll bars (horizontalScrollBar() and verticalScrollBar()). Once you have that pointer, you have access to all the methods and signals available from QScrollBar and QAbstractSlider, including value() and valueChanged().https://stackoverflow.com/questions/15816879/qscrollarea-get-scroll-or-total-offset
-
@mrjj i have developed complete logic for lazy image loading . in that i used left button gesture of QScroll Area . now i stuck at catching scrolling event on gesture like swipe above and below like mobile.
now your approach is new for me so if possible suggest me how to use your approach in below code.... QScrollerProperties qScrollerProperties; QVariant overshootPolicy = QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff); qScrollerProperties.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, overshootPolicy); QScroller* qScroller = QScroller::scroller(ui->scrollArea); qScroller->grabGesture(ui->scrollArea->viewport(), QScroller::LeftMouseButtonGesture); qScroller->setScrollerProperties(qScrollerProperties); .... .... void FileManager::mouseReleaseEvent(QMouseEvent *me) { qDebug()<< "Gesture"<<me->type()<<" "<<(checkevntcount++); if(bMousemoved && bMousepressed) { if( me->type() == QEvent::MouseButtonRelease) { if(Imagecount>0) { if( u8RowIndex < MaxPossibleRow) { qDebug()<< "Gesture"<<me->type(); DisplayImageList(); } } bMousemoved = false; bMousepressed = false; } } else { if(bMousemoved) bMousepressed = false; if(bMousepressed) bMousemoved = false; } if (me->type() == QEvent::Gesture) { qDebug()<< "Gesture"<<me->type(); // return gestureEvent(static_cast<QGestureEvent*>(event)); // return QWidget::event(event); } } ....
-
Hi
Its just a signal so you just connect to itconnect( ui->scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, [](int value){ qDebug() << "scroll:" << value; });
-
Hi
Well is the scrollbars shown?if you disable qScroller->grabGesture(xxx) ( as a test)
Does it work then ?
Its unclear to me if using Gestures disable the scrollbars/ not use them.
-
@mrjj 1] No scroll bar is not shown because i use touch screen on touch i need to scroll up and down.
2] i have removed gesture code and tested but print is not comeNote that i does not want to use visual scroll bar i want single figure up and down scrolling in QScrollArea . i know that on value change signal slot of vertical scroll bar i can add my code. but i my intent is to make scrolling like in mobile's gallery.
-
Ok. I guess when they are not shown they do not scroll either.
So QScroller is not using the scrollbars at all.I dont know how to get scroll amount directly from QScroller currently.
The docs says
"The scrolled QObjects receive a QScrollPrepareEvent whenever the scroller needs to update its geometry information and a QScrollEvent whenever the content of the object should actually be scrolled."But from a fast look, im not sure there is a concreate value to read about how much was scrolled.