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 add swipe gesture on QScrollArea widget ?
QtWS25 Last Chance

How to add swipe gesture on QScrollArea widget ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.4k 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 Qt embedded developer
    #1

    i want to add swipe gesture on QScrollArea. i want to catch event also. if any body know how to add swipe gesture on QScrollArea then let me know . i also want to know how to catch event of swipe up and down.

    raven-worxR 1 Reply Last reply
    0
    • Q Qt embedded developer

      i want to add swipe gesture on QScrollArea. i want to catch event also. if any body know how to add swipe gesture on QScrollArea then let me know . i also want to know how to catch event of swipe up and down.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Qt-embedded-developer
      Are you on a touchscreen? If yes, are you sure it's driver delivers really touch events to the OS. Cheap touch screens rather simulate "single-touch" mouse events.

      https://doc.qt.io/qt-5/gestures-overview.html

      If using mouse events you might want to check QScroller

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #3
        QScrollArea * scroll_area = new QScrollArea( this );
        scroll_area->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
        scroll_area->horizontalScrollBar()->setEnabled( false );
        
        QScroller::grabGesture( scroll_area, QScroller::LeftMouseButtonGesture );
        QScrollerProperties properties = QScroller::scroller( scroll_area )->scrollerProperties();
        QVariant overshoot_policy = QVariant::fromValue< QScrollerProperties::OvershootPolicy >( QScrollerProperties::OvershootAlwaysOff );
        properties.setScrollMetric( QScrollerProperties::VerticalOvershootPolicy, overshoot_policy );
        properties.setScrollMetric( QScrollerProperties::HorizontalOvershootPolicy, overshoot_policy );
        QScroller::scroller( scroll_area )->setScrollerProperties( properties );
        
        Q 1 Reply Last reply
        1
        • JoeCFDJ JoeCFD
          QScrollArea * scroll_area = new QScrollArea( this );
          scroll_area->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
          scroll_area->horizontalScrollBar()->setEnabled( false );
          
          QScroller::grabGesture( scroll_area, QScroller::LeftMouseButtonGesture );
          QScrollerProperties properties = QScroller::scroller( scroll_area )->scrollerProperties();
          QVariant overshoot_policy = QVariant::fromValue< QScrollerProperties::OvershootPolicy >( QScrollerProperties::OvershootAlwaysOff );
          properties.setScrollMetric( QScrollerProperties::VerticalOvershootPolicy, overshoot_policy );
          properties.setScrollMetric( QScrollerProperties::HorizontalOvershootPolicy, overshoot_policy );
          QScroller::scroller( scroll_area )->setScrollerProperties( properties );
          
          Q Offline
          Q Offline
          Qt embedded developer
          wrote on last edited by
          #4

          @JoeCFD how to catch event of QScroller::LeftMouseButtonGesture on swipe up and down ?

          JoeCFDJ 1 Reply Last reply
          0
          • Q Qt embedded developer

            @JoeCFD how to catch event of QScroller::LeftMouseButtonGesture on swipe up and down ?

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            @Qt-embedded-developer you create an instance of QScroller::scroller and connect it to QScroller::stateChanged

            Q 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @Qt-embedded-developer you create an instance of QScroller::scroller and connect it to QScroller::stateChanged

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

              @JoeCFD if possible can you provide example code for it

              JoeCFDJ 1 Reply Last reply
              0
              • Q Qt embedded developer

                @JoeCFD if possible can you provide example code for it

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by
                #7

                @Qt-embedded-developer
                QScroller * scroller = QScroller::scroller( scroll_area );
                scroller->setScrollerProperties( properties );

                connect( scroller, &QScroller:: stateChanged, this, &yourFuncSlot );

                Q 1 Reply Last reply
                0
                • JoeCFDJ JoeCFD

                  @Qt-embedded-developer
                  QScroller * scroller = QScroller::scroller( scroll_area );
                  scroller->setScrollerProperties( properties );

                  connect( scroller, &QScroller:: stateChanged, this, &yourFuncSlot );

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

                  @JoeCFD As per your suggestion i have used below code but in my case on scrolling the slot DisplayImageList1() is not getting called.

                  why stateChanged does not call my slot DisplayImageList1() ?

                  where is mistake done in below code to get desired slot call on scrolling using QScroller::LeftMouseButtonGesture ?

                   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, QScroller::LeftMouseButtonGesture);
                  
                      qScroller->setScrollerProperties(qScrollerProperties);
                  
                  
                      QObject::connect(qScroller, SIGNAL(stateChanged(QScroller::State)),
                                       this,  SLOT(DisplayImageList1()));
                  

                  Note: Above question i asked because on scrolling inside QScrollArea i need to call DisplayImageList1().

                  JoeCFDJ 1 Reply Last reply
                  0
                  • Q Qt embedded developer

                    @JoeCFD As per your suggestion i have used below code but in my case on scrolling the slot DisplayImageList1() is not getting called.

                    why stateChanged does not call my slot DisplayImageList1() ?

                    where is mistake done in below code to get desired slot call on scrolling using QScroller::LeftMouseButtonGesture ?

                     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, QScroller::LeftMouseButtonGesture);
                    
                        qScroller->setScrollerProperties(qScrollerProperties);
                    
                    
                        QObject::connect(qScroller, SIGNAL(stateChanged(QScroller::State)),
                                         this,  SLOT(DisplayImageList1()));
                    

                    Note: Above question i asked because on scrolling inside QScrollArea i need to call DisplayImageList1().

                    JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by
                    #9

                    @Qt-embedded-developer I think you are doing swipe of pictures. Check this example out:
                    https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/gestures/imagegestures?h=5.15

                    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