Results 1 to 3 of 3

Thread: QScrollArea and TouchEvent

  1. #1
    Join Date
    Apr 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QScrollArea and TouchEvent

    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:

    Qt Code:
    1. ScrollArea::ScrollArea(QWidget *parent)
    2. :QScrollArea(parent)
    3. {
    4. setAttribute(Qt::WA_AcceptTouchEvents);
    5. }
    6.  
    7. bool ScrollArea::event(QEvent* event)
    8. {
    9. switch (event->type()) {
    10. case QEvent::TouchBegin:
    11. {
    12. QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
    13. QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
    14. touchPoints.first().setLastPos(touchPoints.first().pos());
    15. }
    16.  
    17. break;
    18. case QEvent::TouchUpdate:
    19. case QEvent::TouchEnd:
    20. {
    21. QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
    22.  
    23. QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
    24. const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
    25. if(touchPoints.count() == 1 && !touchPoint0.lastPos().isNull() )
    26. {
    27. // determine scale factor
    28. QPointF delta = touchPoint0.pos() - touchPoint0.lastPos() ;
    29. if(touchPoint0.lastPos().x() > touchPoint0.pos().x())//old position is qpoint it remembers last position
    30. this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() - delta.x());
    31.  
    32. if(touchPoint0.lastPos().x() < touchPoint0.pos().x())
    33. this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() - delta.x());
    34.  
    35. if(touchPoint0.lastPos().y() > touchPoint0.pos().y())
    36. this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() - delta.y());
    37.  
    38. if(touchPoint0.lastPos().y() < touchPoint0.pos().y())
    39. this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() - delta.y());
    40.  
    41. return true;
    42. }
    43.  
    44. }break;
    45.  
    46. default:
    47. return QWidget::event(event);
    48. break;
    49. }
    50. }
    To copy to clipboard, switch view to plain text mode 

    Of course, I have create my class ToolButton to accept touchEvents:

    Qt Code:
    1. this->setAttribute(Qt::WA_AcceptTouchEvent);
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea and TouchEvent

    Do you want to handle the touch event in the toolbutton? if not then disable the accept touch event, then the event should be propagated to the parent widget (scroll area).
    The touch events will go up the list of parents until one of then accepts the event or uses an eventfilter that consumes the event. Be sure to set the parent on the toolbutton!

  3. #3
    Join Date
    Apr 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QScrollArea and TouchEvent

    Yes I want handle the event in ToolButon so the event no sent to parent ...
    But an handle just for click on the ToolButon.
    Last edited by Francknos; 20th June 2014 at 16:48. Reason: updated contents

Similar Threads

  1. Replies: 4
    Last Post: 2nd December 2010, 07:51
  2. Replies: 0
    Last Post: 1st August 2010, 09:20
  3. QScrollArea
    By franco.amato in forum Qt Programming
    Replies: 10
    Last Post: 6th January 2010, 21:19
  4. Replies: 2
    Last Post: 10th March 2008, 21:16
  5. QScrollArea ?
    By whitefurrows in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 23:15

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.