Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Swipe gesture for forms transition
Forum Updated to NodeBB v4.3 + New Features

Swipe gesture for forms transition

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 307 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.
  • A Offline
    A Offline
    Andreagugu
    wrote on last edited by
    #1

    Hello,
    I'm trying to implement a transition between forms with swipe gesture.
    I followed some instruction found on the web but it doesn't work as expected.

    This is my code:
    File hpp:

    #ifndef PAGEINTRO_HPP
    #define PAGEINTRO_HPP
    
    #include <QDialog>
    #include <QSwipeGesture>
     #include <QtGui>
    
    namespace Ui {
    class PageIntro;
    }
    
    class PageIntro : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit PageIntro(QWidget *parent = 0);
        ~PageIntro();
        bool gestureEvent(QGestureEvent *event);
        void swipeTriggered(QSwipeGesture*);
    
    private slots:
        void on_pushButton_clicked();
    
    protected:
         bool event(QEvent *event);
    
    private:
        Ui::PageIntro *ui;
    };
    
    #endif // PAGEINTRO_HPP
    
    

    File cpp:

    #include "PageIntro.hpp"
    #include "ui_PageIntro.h"
    
    PageIntro::PageIntro(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::PageIntro)
    {
        setAttribute(Qt::WA_AcceptTouchEvents);
        setAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
    
        grabGesture(Qt::SwipeGesture);
        ui->setupUi(this);
    }
    
    PageIntro::~PageIntro()
    {
        delete ui;
    }
    
    void PageIntro::on_pushButton_clicked()
    {
        this->close();
    }
    
    bool PageIntro::event(QEvent *event)
    {
        if (event->type() == QEvent::Gesture)
            return gestureEvent(static_cast<QGestureEvent*>(event));
        return QWidget::event(event);
    }
    
    bool PageIntro::gestureEvent(QGestureEvent *event)
    {
        if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
            swipeTriggered(static_cast<QSwipeGesture *>(swipe));
        return true;
    }
    
    void PageIntro::swipeTriggered(QSwipeGesture *gesture)
    {
        if (gesture->state() == Qt::GestureFinished) {
            if (gesture->horizontalDirection() == QSwipeGesture::Left
                || gesture->verticalDirection() == QSwipeGesture::Up)
                this->close();
            else
                this->close();
            update();
        }
    }
    
    

    Very simple but...
    The issue is that the event seems recognized, or at least some events are recognized but not the gesture I' searching.
    In debug the event is raised but the type() is not showed.. don't know which is but the IF is not verified, so is not my swipe.

    It's possible to activate and handle a gesture for the whole form? ..or I should activate it under a specific widget?

    Bye
    Andrea

    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