QGraphicsView scrolls unexpectedly after a QTouchEvent



  • I'm implementing an image viewer on an embedded platform. The hardware is a sort of tablet and has a touch screen as input device. The Qt version I'm using is 5.4.3.

    The QGraphicsView is used to display a QGraphicsScene which contains a QGraphicsPixmapItem. The QGraphicsPixmapItem containts the pixmap to display.

    The relevant part of the code is the following:

    void MyGraphicsView::pinchTriggered(QPinchGesture *gesture)
    {
    QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags();
    
    if (changeFlags & QPinchGesture::ScaleFactorChanged) {
        currentStepScaleFactor = gesture->totalScaleFactor();
    }
    
    if (gesture->state() == Qt::GestureFinished) {
        scaleFactor *= currentStepScaleFactor;
        currentStepScaleFactor = 1;
        return;
    }
    
    // Compute the scale factor based on the current pinch level
    qreal sxy = scaleFactor * currentStepScaleFactor;
    
    // Get the pointer to the currently displayed picture
    QList<QGraphicsItem *> listOfItems = items();
    QGraphicsItem* item = listOfItems.at(0);
    
    // Scale the picture
    item.setScale(sxy);
    
    // Adapt the scene to the scaled picture
    setSceneRect(scene()->itemsBoundingRect());
    }
    

    After the pinch a touch on the screen causes a strange behaviour. The view scrolls unexpectedly causing a bad glitch.

    Below the events that are dispatched to the scene during the pinch action and subsequent touch:

    // Pinch action
    MyGraphicsScene::event - Event  8 , accepted
    MyGraphicsScene::event - Event  194 , accepted
    MyGraphicsScene::event - Event  10 , not accepted
    MyGraphicsScene::event - Event  156 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  43 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  43 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  43 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  43 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  43 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  43 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  43 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  43 , accepted
    MyGraphicsScene::event - Event  198 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  198 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  198 , accepted
    MyGraphicsScene::event - Event  196 , accepted
    MyGraphicsScene::event - Event  43 , accepted
    
    // Touch action which causes the problem
    MyGraphicsScene::event - Event  194 , accepted
    MyGraphicsScene::event - Event  195 , accepted
    MyGraphicsScene::event - Event  196 , accepted
    MyGraphicsScene::event - Event  157 , accepted
    

    where:

    TouchBegin = 194,
    TouchUpdate = 195,
    TouchEnd = 196,
    GraphicsSceneMousePress = 156,
    GraphicsSceneMouseRelease = 157,
    

    It seems that when the glitch appears the GraphicsSceneMousePress event (=156) is not dispatched to the scene.

    Which is the cause of the problem? Is it a bug of the QGraphicsView/QGraphicsScene/QGraphicsPixmap objects? How to fix the problem?

    Thanks in advance

    Best regards


  • Lifetime Qt Champion

    Hi,

    Before going on a bug hunt, you should try with a more recent version of Qt the current it 5.5.1 with 5.6.0 in beta.



  • @SGaist I'm sorry but the Qt version in use is freezed and I can not switch



  • I've made further investigations debugging the touch controller in use.

    The sequence of touches which causes the problem is:

    • touch with the thumb
    • touch at the same time with the forefinger (gesture started)
    • remove the thumb
    • remove the forefinger (gesture ended)

    At this point if I execute a new touch on the screen the glitch appears.

    The glitch is NOT present if using the subsequent sequence:

    • touch with the thumb
    • touch at the same time with the forefinger (gesture started)
    • remove the forefinger
    • remove the thumb (gesture ended)

    Below a log of my touch controller related to the two sequences.

    Sequence which causes the problem:
    // Touch with the thumb
    Event: time 1451525078.959483, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 2023
    Event: time 1451525078.959483, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 13264
    Event: time 1451525078.959483, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 7824
    Event: time 1451525078.959483, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
    Event: time 1451525078.959483, type 3 (EV_ABS), code 0 (ABS_X), value 13264
    Event: time 1451525078.959483, type 3 (EV_ABS), code 1 (ABS_Y), value 7824
    Event: time 1451525078.959483, -------------- SYN_REPORT ------------

    // Touch at the same time with the forefinger (gesture started)
    Event: time 1451525081.378908, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 1
    Event: time 1451525081.378908, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 2024
    Event: time 1451525081.378908, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 18016
    Event: time 1451525081.378908, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 15392
    Event: time 1451525081.378908, -------------- SYN_REPORT ------------

    // Remove the thumb
    Event: time 1451525083.165372, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 0
    Event: time 1451525083.165372, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 13280
    Event: time 1451525083.165372, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 7840
    Event: time 1451525083.165372, type 3 (EV_ABS), code 0 (ABS_X), value 13280
    Event: time 1451525083.165372, type 3 (EV_ABS), code 1 (ABS_Y), value 7840
    Event: time 1451525083.165372, -------------- SYN_REPORT ------------
    Event: time 1451525083.167019, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
    Event: time 1451525083.167019, type 3 (EV_ABS), code 0 (ABS_X), value 18016
    Event: time 1451525083.167019, type 3 (EV_ABS), code 1 (ABS_Y), value 15392
    Event: time 1451525083.167019, -------------- SYN_REPORT ------------

    // Remove the forefinger (gesture ended)
    Event: time 1451525084.879579, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 1
    Event: time 1451525084.879579, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 15456
    Event: time 1451525084.879579, type 3 (EV_ABS), code 1 (ABS_Y), value 15456
    Event: time 1451525084.879579, -------------- SYN_REPORT ------------
    Event: time 1451525084.881247, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
    Event: time 1451525084.881247, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
    Event: time 1451525084.881247, -------------- SYN_REPORT ------------

    // New touch which causes the glitch
    Event: time 1451525443.035846, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 0
    Event: time 1451525443.035846, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 2027
    Event: time 1451525443.035846, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 11088
    Event: time 1451525443.035846, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 10816
    Event: time 1451525443.035846, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
    Event: time 1451525443.035846, type 3 (EV_ABS), code 0 (ABS_X), value 11088
    Event: time 1451525443.035846, type 3 (EV_ABS), code 1 (ABS_Y), value 10816
    Event: time 1451525443.035846, -------------- SYN_REPORT ------------
    Event: time 1451525443.927823, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 10832
    Event: time 1451525443.927823, type 3 (EV_ABS), code 1 (ABS_Y), value 10832
    Event: time 1451525443.927823, -------------- SYN_REPORT ------------
    Event: time 1451525443.929448, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
    Event: time 1451525443.929448, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
    Event: time 1451525443.929448, -------------- SYN_REPORT ------------


  • Lifetime Qt Champion

    While I understand the version freeze, you should anyway take a look at the state with a more recent version. That way if the bug disappeared you know you can check Qt's sources to find what was changed and maybe rebuild Qt with the patches in place.



  • For anyone stumbling upon this thread (as I did) while experiencing strange pinch/mouse behaviour as described.

    It is still an unresolved problem in Qt 5.9.5 at least, and seems to have been resolved in 5.11 beta 4 (or somewhere in between).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.