Overriding of QWidget::event not working!!



  • Hey there,

    i am trying to override the default behavoiur of QWidget::event.
    I am trying to implement some touch features.

    On my widget i made sure to set setAttribute(Qt::WA_AcceptTouchEvents);

    Now from the docs, i read that Qt generates for the first non-primary touchpoint also a mouse event.
    I am simply trying to avoid this.
    I am using a default example of QT. You can find it in the example/touch directory shipped with QT.

    Here is my Code. Note that i am not calling the default behaviour of QWidget. I accept all touchevents and return true so clarify that i have handled the touchevent.

    [CODE]
    bool ScribbleArea::event(QEvent event)
    {
    bool handleEvent = false;
    QInputEvent
    inPut = dynamic_cast<QInputEvent*>(event);
    if(inPut)
    {
    switch (inPut ->type())
    {
    case QEvent::TouchBegin:
    std::cout<<"ScribbleArea received TouchEvent BEGIN";
    inPut->accept();
    handleEvent=true;
    break;
    case QEvent::TouchUpdate:
    //std::cout<<"ScribbleArea received TouchEvent UPDATE";
    inPut->accept();
    handleEvent=true;
    break;
    case QEvent::TouchEnd:
    std::cout<<"ScribbleArea received TouchEvent END";
    inPut->accept();
    handleEvent=true;
    break;
    case QEvent::MouseButtonPress:
    std::cout<<"ScribbleArea received MouseEvent PRESS";
    break;
    case QEvent::MouseButtonRelease:
    std::cout<<"ScribbleArea received MouseEvent RELEASE";
    break;
    }
    return handleEvent;
    }
    return true;
    }
    [/CODE]

    However, what i get is this, when i am simply touching the screen once.
    Why is this? I dont want the mouse event to be generated by QT.

    [CODE]
    std::cout<<"ScribbleArea received TouchEvent";
    std::cout<<"ScribbleArea received MouseEvent PRESS";
    std::cout<<"ScribbleArea received TouchEvent END";
    std::cout<<"ScribbleArea received MouseEvent RELEASE";
    [/CODE]

    Thanks so far.



  • Read the documentation under the heading Mouse Events and the Primary Touch Point.

    "Documentation":http://qt-project.org/doc/qt-4.8/qtouchevent.html#details


Log in to reply
 

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