Tôi đã thử một "Ví dụ về cử chỉ hình ảnh" từ http://doc.qt.digia.com/4.6/gestures-imagegestures.html. Trong ví dụ này bạn chỉ có 3 cử chỉ: PanGesture, PinchGesture và SwipeGesture. Nhưng Qt cung cấp 5 Gestures:Qt, Cử chỉ. TapAndHold và Vuốt không được nhận dạng
- TapGesture
- TapAndHoldGesture
- PanGesture
- PinchGesture
- SwipeGesture
Để nhận ra tất cả 5 cử chỉ chúng ta cần phải viết vào ImageWidget-Constructor :
grabGesture(Qt::TapGesture);
grabGesture(Qt::TapAndHoldGesture);
grabGesture(Qt::PanGesture);
grabGesture(Qt::PinchGesture);
grabGesture(Qt::SwipeGesture);
tôi thêm một phương thức gestureEvent() cũng
bool ImageWidget::gestureEvent(QGestureEvent *event)
{
if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
swipeTriggered(static_cast<QSwipeGesture *>(swipe));
else if (QGesture *pan = event->gesture(Qt::PanGesture))
panTriggered(static_cast<QPanGesture *>(pan));
if (QGesture *pinch = event->gesture(Qt::PinchGesture))
pinchTriggered(static_cast<QPinchGesture *>(pinch));
if (QGesture *tap = event->gesture(Qt::TapGesture))
tapTriggered(static_cast<QTapGesture *>(tap));
if (QGesture *tapandhold = event->gesture(Qt::TapAndHoldGesture))
{
tapandholdTriggered(static_cast<QTapAndHoldGesture *>(tapandhold));
}
return true;
}
và viết phương pháp thiếu như
void ImageWidget::tapTriggered(QTapGesture *gesture)
{
qDebug() << "TAP" << gesture->position();
}
void ImageWidget::tapandholdTriggered(QTapAndHoldGesture *tapandhold)
{
qDebug() << "TAPANDHOLD";
}
vậy, câu hỏi của tôi là, tại sao những cử chỉ vuốt và TapAndHold không được công nhận? Những cử chỉ này được thực hiện như nhau như ba cử chỉ được nhận dạng (Pan, Pinch và Tap). Tại sao nó không hoạt động?
Tôi cảm ơn bạn trước cho sự giúp đỡ
Bạn đã tính toán điều này chưa? Tôi cũng đang cố gắng hiểu cử chỉ chụp trong một QListWidget. –
Bạn đã giải quyết vấn đề này chưa? Tôi cũng phải đối mặt với cùng một vấn đề. – Tarantula