PDA

View Full Version : TapAndHoldGesture sender object name



giovanni.foiani
5th March 2013, 10:08
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:



bool RecipeList::event(QEvent *event)
{
if (event->type() == QEvent::Gesture) {
return gestureEvent(static_cast<QGestureEvent*>(event));
}
return QWidget::event(event);
}

bool RecipeList::gestureEvent(QGestureEvent *event)
{
if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
swipeTriggered(static_cast<QSwipeGesture*>(swipe));
else if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture))
tapAndHoldTriggered(static_cast<QTapAndHoldGesture*>(tapAndHold));
return true;
}

void RecipeList::tapAndHoldTriggered(QTapAndHoldGesture * tapAndHold)
{
if (tapAndHold->state() == Qt::GestureFinished) {
QLOG_DEBUG() << Q_FUNC_INFO;
}
}


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

Thanks

Giovanni

giovanni.foiani
5th March 2013, 15:14
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)



buttonWidget->grabGesture(Qt::TapAndHoldGesture);
buttonWidget->installEventFilter(this);


And then the handling code:



bool RecipeList::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::Gesture) {
return gestureEvent(obj, static_cast<QGestureEvent*>(event));
}
return QWidget::eventFilter(obj, event);
}

bool RecipeList::gestureEvent(QObject *obj, QGestureEvent *event)
{
if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
swipeTriggered(obj, static_cast<QSwipeGesture*>(swipe));
else if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture))
tapAndHoldTriggered(obj, static_cast<QTapAndHoldGesture*>(tapAndHold));
return true;
}

void RecipeList::tapAndHoldTriggered(QObject *obj, QTapAndHoldGesture* tapAndHold)
{
if (tapAndHold->state() == Qt::GestureFinished) {
QLOG_DEBUG() << obj->objectName();
}
}


Giovanni

JandunCN
19th December 2013, 10:15
Thanks,it is helpful to me.