Results 1 to 3 of 3

Thread: TapAndHoldGesture sender object name

  1. #1
    Join Date
    Aug 2012
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt/Embedded

    Default TapAndHoldGesture sender object name

    Hi,

    I'm handling TapAndHoldGesture in my Qt Application (version 4.7.4), the gesture is correctly fired and I handle it in the following way:

    Qt Code:
    1. bool RecipeList::event(QEvent *event)
    2. {
    3. if (event->type() == QEvent::Gesture) {
    4. return gestureEvent(static_cast<QGestureEvent*>(event));
    5. }
    6. return QWidget::event(event);
    7. }
    8.  
    9. bool RecipeList::gestureEvent(QGestureEvent *event)
    10. {
    11. if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
    12. swipeTriggered(static_cast<QSwipeGesture*>(swipe));
    13. else if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture))
    14. tapAndHoldTriggered(static_cast<QTapAndHoldGesture*>(tapAndHold));
    15. return true;
    16. }
    17.  
    18. void RecipeList::tapAndHoldTriggered(QTapAndHoldGesture* tapAndHold)
    19. {
    20. if (tapAndHold->state() == Qt::GestureFinished) {
    21. QLOG_DEBUG() << Q_FUNC_INFO;
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    I need to extract the event sender object name, I tried sender()->objectName() but it fails.
    How can I make it work?

    Thanks

    Giovanni

  2. #2
    Join Date
    Aug 2012
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt/Embedded

    Default Re: TapAndHoldGesture sender object name

    I solved using event filter on widget on which I want to catch TapAndHoldGesture.

    I installed event filter in this way: (buttonWidget is the widget that fires TapAndHoldGesture)

    Qt Code:
    1. buttonWidget->grabGesture(Qt::TapAndHoldGesture);
    2. buttonWidget->installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 

    And then the handling code:

    Qt Code:
    1. bool RecipeList::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if (event->type() == QEvent::Gesture) {
    4. return gestureEvent(obj, static_cast<QGestureEvent*>(event));
    5. }
    6. return QWidget::eventFilter(obj, event);
    7. }
    8.  
    9. bool RecipeList::gestureEvent(QObject *obj, QGestureEvent *event)
    10. {
    11. if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
    12. swipeTriggered(obj, static_cast<QSwipeGesture*>(swipe));
    13. else if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture))
    14. tapAndHoldTriggered(obj, static_cast<QTapAndHoldGesture*>(tapAndHold));
    15. return true;
    16. }
    17.  
    18. void RecipeList::tapAndHoldTriggered(QObject *obj, QTapAndHoldGesture* tapAndHold)
    19. {
    20. if (tapAndHold->state() == Qt::GestureFinished) {
    21. QLOG_DEBUG() << obj->objectName();
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    Giovanni

  3. The following user says thank you to giovanni.foiani for this useful post:

    JandunCN (19th December 2013)

  4. #3
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: TapAndHoldGesture sender object name

    Thanks,it is helpful to me.

Similar Threads

  1. Dbus -Unique sender id?
    By tyrnikeisari in forum Qt Programming
    Replies: 1
    Last Post: 8th May 2011, 23:09
  2. qobject_cast and sender()
    By ksrarc in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2009, 16:57
  3. problem in sender()
    By wagmare in forum Qt Programming
    Replies: 13
    Last Post: 15th July 2009, 10:04
  4. tip on using QObject::sender()
    By drhex in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2008, 20:01
  5. question about the use of sender( ) function
    By luffy27 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 08:15

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.