Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Overriding of QWidget::event not working!!
Forum Updated to NodeBB v4.3 + New Features

Overriding of QWidget::event not working!!

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kinglui987
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      steno
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved