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. QScrollArea and TouchEvent

QScrollArea and TouchEvent

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.1k 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.
  • F Offline
    F Offline
    Francknos
    wrote on last edited by
    #1

    Hello,

    My problem today is about tactil event on QScrollArea.
    My view has:

    One ScrollArea which contain some ToolButton

    I create my class ScrollArea like this:
    @
    ScrollArea::ScrollArea(QWidget *parent)
    :QScrollArea(parent)
    {
    setAttribute(Qt::WA_AcceptTouchEvents);
    }

    bool ScrollArea::event(QEvent* event)
    {
    switch (event->type()) {
    case QEvent::TouchBegin:
    {
    QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
    QListQTouchEvent::TouchPoint touchPoints = touchEvent->touchPoints();
    touchPoints.first().setLastPos(touchPoints.first().pos());
    }

        break;
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
        QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
    
        QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
        const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
        if(touchPoints.count() == 1 && !touchPoint0.lastPos().isNull() )
        {
            // determine scale factor
            QPointF delta = touchPoint0.pos() - touchPoint0.lastPos() ;
            if(touchPoint0.lastPos().x() > touchPoint0.pos().x())//old position is qpoint it remembers last position
                this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() - delta.x());
    
            if(touchPoint0.lastPos().x() < touchPoint0.pos().x())
                this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() - delta.x());
    
            if(touchPoint0.lastPos().y() > touchPoint0.pos().y())
                this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() - delta.y());
    
            if(touchPoint0.lastPos().y() < touchPoint0.pos().y())
                this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() - delta.y());
    
            return true;
        }
    
    }break;
    
    default:
        return QWidget::event(event);
        break;
    }
    

    }
    @

    Of course, I have create my class ToolButton to accept touchEvents:
    @this->setAttribute(Qt::WA_AcceptTouchEvent);@

    The scroll works fine if the start of my touch is on the background of ScrollArea. If my first touch begin on ToolButton, the event is not sent to my parent (here ScrollArea).

    Someone can help me?

    Thanks.

    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