Results 1 to 13 of 13

Thread: Overriding QWidget::event does not work!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    18
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Overriding QWidget::event does not work!

    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.

    Qt Code:
    1. bool ScribbleArea::event(QEvent *event)
    2. {
    3. bool handleEvent = false;
    4. QInputEvent* inPut = dynamic_cast<QInputEvent*>(event);
    5. if(inPut)
    6. {
    7. switch (inPut ->type())
    8. {
    9. case QEvent::TouchBegin:
    10. std::cout<<"ScribbleArea received TouchEvent BEGIN";
    11. inPut->accept();
    12. handleEvent=true;
    13. break;
    14. case QEvent::TouchUpdate:
    15. //std::cout<<"ScribbleArea received TouchEvent UPDATE";
    16. inPut->accept();
    17. handleEvent=true;
    18. break;
    19. case QEvent::TouchEnd:
    20. std::cout<<"ScribbleArea received TouchEvent END";
    21. inPut->accept();
    22. handleEvent=true;
    23. break;
    24. case QEvent::MouseButtonPress:
    25. std::cout<<"ScribbleArea received MouseEvent PRESS";
    26. break;
    27. case QEvent::MouseButtonRelease:
    28. std::cout<<"ScribbleArea received MouseEvent RELEASE";
    29. break;
    30. }
    31. return handleEvent;
    32. }
    33. return true;
    34. }
    To copy to clipboard, switch view to plain text mode 

    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.

    Qt Code:
    1. std::cout<<"ScribbleArea received TouchEvent";
    2. std::cout<<"ScribbleArea received MouseEvent PRESS";
    3. std::cout<<"ScribbleArea received TouchEvent END";
    4. std::cout<<"ScribbleArea received MouseEvent RELEASE";
    To copy to clipboard, switch view to plain text mode 

    Thanks so far.
    Last edited by kinglui987; 28th January 2013 at 10:34.

Similar Threads

  1. QWidget::update does not work!
    By sapali in forum Qt Programming
    Replies: 8
    Last Post: 17th March 2011, 16:56
  2. Replies: 1
    Last Post: 16th September 2010, 15:57
  3. QWidget Shown Event
    By perq in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2010, 15:20
  4. overriding the QWidget::contextMenuEvent
    By smarinr in forum Qt Programming
    Replies: 1
    Last Post: 9th May 2008, 21:16
  5. Getting QWidget::windowIcon to work
    By graeme in forum Qt Tools
    Replies: 7
    Last Post: 2nd April 2006, 14:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.