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. Swipe Gesture
Forum Updated to NodeBB v4.3 + New Features

Swipe Gesture

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.7k Views 1 Watching
  • 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.
  • HollyJH Offline
    HollyJH Offline
    HollyJ
    wrote on last edited by
    #1

    Hi:
    Well, I´m new in this forum but some of the topics that are in the site have been so helpful. Just like this one:
    Re: Qt Swipe Gesture not working
    I´ve already follow all the instruccions and it work!! But i´ve been wondering if you can do it backwards I mean, that the swipe move to left to right like if you wanted to go back to the last stacked page you saw.
    Somebody could help me with this?
    Thanks.

    J.HilkJ 1 Reply Last reply
    0
    • HollyJH HollyJ

      Hi:
      Well, I´m new in this forum but some of the topics that are in the site have been so helpful. Just like this one:
      Re: Qt Swipe Gesture not working
      I´ve already follow all the instruccions and it work!! But i´ve been wondering if you can do it backwards I mean, that the swipe move to left to right like if you wanted to go back to the last stacked page you saw.
      Somebody could help me with this?
      Thanks.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @HollyJ
      hi,
      I made a full single finger swipe-Stackwidget a while ago, sadly I'm not allowed to share it.

      But that doesn't stop me from giving help, when its needed :-)

      Why don't you post what you have, what is working and where you have problems? As a code example, makes it easier for everyone to help/understand.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • HollyJH Offline
        HollyJH Offline
        HollyJ
        wrote on last edited by
        #3

        I´ve this swipe menu:

        bool Data1::eventFilter(QObject *, QEvent *event)
        {
        static bool Start = False;
        static int xpos_start=0;
        int xpos;
        int diff_xpos;
        static qint64 mSec;
        int TotalPages;

        QMouseEvent mouseevent = static_cast<QMouseEvent>(mouseevent);
        
        if((event->type()==QEvent::MouseButtonPress)&&(Start==False))
        {
            Start = True;
            timer.restart();
            xpos_start=mouseevent.pos().x();
        }
        else if((event->type()==QEvent::MouseButtonRelease)&&(Start==True))
        {
            Start=False;
            xpos=mouseevent.pos().x();
            diff_xpos=xpos_start-xpos;
            mSec=timer.elapsed();
            if((abs(diff_xpos)>300)&&(mSec<200))
            {
               if(diff_xpos<0)
               {
                   TotalPages=ui->stackedWidget_2->count();
                   if(mindex<TotalPages-1)
                       mindex++;
                   else
                       mindex=0;
                   ui->stackedWidget_2->setCurrentIndex(mindex);
               }
               else
               {
                   TotalPages=ui->stackedWidget_2->count();
                   if(mindex==0)
                   {
                       mindex--;
                   }
                   ui->stackedWidget_2->setCurrentIndex(mindex);
               }
            }
        }
        else if(event->type()==QEvent::MouseMove)
        {
            //QStatusBar().showMessage(QString("Mouse move (%1,%2)").arg(mouseevent.pos().x()).arg(mouseevent.pos().y()));
            qDebug()<<QString::number(mouseevent.pos().x());
            qDebug()<<QString::number(mouseevent.pos().y());
        }
        
        return false;
        

        }

        And it works when I click on everywhere on the right. And displace the pages from left to right. I want something to do this but backwards (right to left)cor that you can return.
        Thank you for helping me

        J.HilkJ 1 Reply Last reply
        0
        • HollyJH HollyJ

          I´ve this swipe menu:

          bool Data1::eventFilter(QObject *, QEvent *event)
          {
          static bool Start = False;
          static int xpos_start=0;
          int xpos;
          int diff_xpos;
          static qint64 mSec;
          int TotalPages;

          QMouseEvent mouseevent = static_cast<QMouseEvent>(mouseevent);
          
          if((event->type()==QEvent::MouseButtonPress)&&(Start==False))
          {
              Start = True;
              timer.restart();
              xpos_start=mouseevent.pos().x();
          }
          else if((event->type()==QEvent::MouseButtonRelease)&&(Start==True))
          {
              Start=False;
              xpos=mouseevent.pos().x();
              diff_xpos=xpos_start-xpos;
              mSec=timer.elapsed();
              if((abs(diff_xpos)>300)&&(mSec<200))
              {
                 if(diff_xpos<0)
                 {
                     TotalPages=ui->stackedWidget_2->count();
                     if(mindex<TotalPages-1)
                         mindex++;
                     else
                         mindex=0;
                     ui->stackedWidget_2->setCurrentIndex(mindex);
                 }
                 else
                 {
                     TotalPages=ui->stackedWidget_2->count();
                     if(mindex==0)
                     {
                         mindex--;
                     }
                     ui->stackedWidget_2->setCurrentIndex(mindex);
                 }
              }
          }
          else if(event->type()==QEvent::MouseMove)
          {
              //QStatusBar().showMessage(QString("Mouse move (%1,%2)").arg(mouseevent.pos().x()).arg(mouseevent.pos().y()));
              qDebug()<<QString::number(mouseevent.pos().x());
              qDebug()<<QString::number(mouseevent.pos().y());
          }
          
          return false;
          

          }

          And it works when I click on everywhere on the right. And displace the pages from left to right. I want something to do this but backwards (right to left)cor that you can return.
          Thank you for helping me

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @HollyJ
          ah, the eventFilter approach, interesting:

          From what I see, the swipe back functionality is this part

          else
                 {
                     TotalPages=ui->stackedWidget_2->count();
                     if(mindex==0)
                     {
                         mindex--;
                     }
                     ui->stackedWidget_2->setCurrentIndex(mindex);
                 }
          

          and you would have to change that.

          You will have to remember the previous index bevor you change inte index and fall back to that
          e.g:

          else if((event->type()==QEvent::MouseButtonRelease)&&(Start==True))
          {
              Start=False;
              xpos=mouseevent.pos().x();
              diff_xpos=xpos_start-xpos;
              mSec=timer.elapsed();
              if((abs(diff_xpos)>300)&&(mSec<200))
              {
                 if(diff_xpos<0)
                 {
                     TotalPages=ui->stackedWidget_2->count();
                     if(mindex<TotalPages-1)
                         mindex++;
                     else
                         mindex=0;
                     lastIndex = ui->stackedWidget_2->currentIndex();
                     ui->stackedWidget_2->setCurrentIndex(mindex);
                 }
                 else
                 {
                     ui->stackedWidget_2->setCurrentIndex(lastIndex);
                 }
              }
          }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          HollyJH 1 Reply Last reply
          2
          • J.HilkJ J.Hilk

            @HollyJ
            ah, the eventFilter approach, interesting:

            From what I see, the swipe back functionality is this part

            else
                   {
                       TotalPages=ui->stackedWidget_2->count();
                       if(mindex==0)
                       {
                           mindex--;
                       }
                       ui->stackedWidget_2->setCurrentIndex(mindex);
                   }
            

            and you would have to change that.

            You will have to remember the previous index bevor you change inte index and fall back to that
            e.g:

            else if((event->type()==QEvent::MouseButtonRelease)&&(Start==True))
            {
                Start=False;
                xpos=mouseevent.pos().x();
                diff_xpos=xpos_start-xpos;
                mSec=timer.elapsed();
                if((abs(diff_xpos)>300)&&(mSec<200))
                {
                   if(diff_xpos<0)
                   {
                       TotalPages=ui->stackedWidget_2->count();
                       if(mindex<TotalPages-1)
                           mindex++;
                       else
                           mindex=0;
                       lastIndex = ui->stackedWidget_2->currentIndex();
                       ui->stackedWidget_2->setCurrentIndex(mindex);
                   }
                   else
                   {
                       ui->stackedWidget_2->setCurrentIndex(lastIndex);
                   }
                }
            }
            
            HollyJH Offline
            HollyJH Offline
            HollyJ
            wrote on last edited by
            #5

            Hi @J-Hilk
            Thank you so much for answer me too soon. I´ve already try all what you wrote but it still working in the same way. Any suggestions? Or what I´m doing wrong?

            J.HilkJ 1 Reply Last reply
            0
            • HollyJH HollyJ

              Hi @J-Hilk
              Thank you so much for answer me too soon. I´ve already try all what you wrote but it still working in the same way. Any suggestions? Or what I´m doing wrong?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @HollyJ
              well, I could only guess :-)

              Post what you wrote, hand how it behaves differently from what you want it to do.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              0
              • HollyJH Offline
                HollyJH Offline
                HollyJ
                wrote on last edited by
                #7

                Hi, sorry for the late respond but if some wants to do a swipe on stacked widget with buttons this is the code that works for me:
                On right button:
                curr = this->ui->YourSwipedpage->currentIndex();
                this->ui->YouSwipepage->setCurrentIndex(curr+1);
                On Left Button:
                curr = this->ui->YourSwipePage->currentIndex();
                this->ui->YourSwipePage->setCurrentIndex(curr-1);

                Thanks to J.Hilk for all his help

                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