Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to catch event of scrolling inside QScrollArea ?

How to catch event of scrolling inside QScrollArea ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by
    #1

    i want to add slot on 'scrolling' inside QScrollArea. if anybody know how to achieve this then let me know.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Q 1 Reply Last reply
      1
      • mrjjM mrjj

        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

        Q Offline
        Q Offline
        Qt embedded developer
        wrote on last edited by
        #3

        @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);
            }
        }
        ....
        
        
        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Its just a signal so you just connect to it

           connect( ui->scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, [](int value){
                  qDebug() << "scroll:" << value;
              });
          
          
          Q 1 Reply Last reply
          2
          • mrjjM mrjj

            Hi
            Its just a signal so you just connect to it

             connect( ui->scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, [](int value){
                    qDebug() << "scroll:" << value;
                });
            
            
            Q Offline
            Q Offline
            Qt embedded developer
            wrote on last edited by
            #5

            @mrjj hi i have used your suggested code. but its debug is not get printed. why on scroll this value not get printed.

            mrjjM 1 Reply Last reply
            0
            • Q Qt embedded developer

              @mrjj hi i have used your suggested code. but its debug is not get printed. why on scroll this value not get printed.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Qt-embedded-developer

              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.

              Q 1 Reply Last reply
              0
              • mrjjM mrjj

                @Qt-embedded-developer

                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.

                Q Offline
                Q Offline
                Qt embedded developer
                wrote on last edited by Qt embedded developer
                #7

                @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 come

                Note 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.

                mrjjM 1 Reply Last reply
                0
                • Q Qt embedded developer

                  @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 come

                  Note 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.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Qt-embedded-developer

                  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.

                  Q 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    @Qt-embedded-developer

                    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.

                    Q Offline
                    Q Offline
                    Qt embedded developer
                    wrote on last edited by
                    #9

                    @mrjj THANK YOU

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved