PinchGesture 手势在自定义的GraphicsItem 上失效

来源:互联网 发布:linux 增量拷贝 编辑:程序博客网 时间:2024/06/10 06:00

  在 GraphicsScene 中 添加   TextItem, PixmapItem,  和用于绘制线段的自定义 drawingView  (继承至 QGraphicsItem)

 在使用 手势处理时, drawingView,PinchGesture 无响应, 事件接收上出现阻隔。


解决方法:  1 .对于 drawingView,  本质为 Item 需要确保其能够接收touch事件, 因此,需要设置:

                         this->setAcceptTouchEvents(true);
                 2. 需要重新实现 bool sceneEvent(QEvent*evnet);



 bool sceneEvent(QEvent*evnet){    QGestureEvent* pGestureEvent ;    switch (event->type()) {    case QEvent::TouchBegin:        event->accept();        return true;    case QEvent::Gesture:        pGestureEvent = static_cast<QGestureEvent*>(event);        if(QGesture *pinch = pGestureEvent->gesture(Qt::PinchGesture)) {            qDebug(" Pinch Gesture: state: %d", pinch->state());        }        break;    default:        break;    }    return QGraphicsItem::sceneEvent(event);}

0 0
原创粉丝点击