Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Overriding of QWidget::event not working!!

    General and Desktop
    2
    2
    4302
    Loading More Posts
    • 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
      kinglui987 last edited by

      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 Reply Quote 0
      • S
        steno last edited by

        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 Reply Quote 0
        • First post
          Last post