Results 1 to 13 of 13

Thread: Overriding QWidget::event does not work!

Hybrid 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 Re: Overriding QWidget::event does not work!

    Hey,

    that was also my first consideration, but after having a look in QWidget::event, i found this:

    Qt Code:
    1. ....
    2.  
    3. case QEvent::TouchBegin:
    4. case QEvent::TouchUpdate:
    5. case QEvent::TouchEnd:
    6. {
    7. #ifndef Q_WS_MAC
    8. QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
    9. const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first();
    10. if (touchPoint.isPrimary() || touchEvent->deviceType() == QTouchEvent::TouchPad)
    11. break;
    12.  
    13. // fake a mouse event!
    14. QEvent::Type eventType = QEvent::None;
    15. switch (touchEvent->type()) {
    16. case QEvent::TouchBegin:
    17. eventType = QEvent::MouseButtonPress;
    18. break;
    19. case QEvent::TouchUpdate:
    20. eventType = QEvent::MouseMove;
    21. break;
    22. case QEvent::TouchEnd:
    23. eventType = QEvent::MouseButtonRelease;
    24. break;
    25. default:
    26. Q_ASSERT(!true);
    27. break;
    28. }
    29. if (eventType == QEvent::None)
    30. break;
    31.  
    32. QMouseEvent mouseEvent(eventType,
    33. touchPoint.pos().toPoint(),
    34. touchPoint.screenPos().toPoint(),
    35. Qt::LeftButton,
    36. Qt::LeftButton,
    37. touchEvent->modifiers());
    38. (void) QApplication::sendEvent(this, &mouseEvent);
    39. #endif // Q_WS_MAC
    40. break;
    41.  
    42. ...
    To copy to clipboard, switch view to plain text mode 

    I am on Windows7 with QT 4.8.3! Dont know if it changed later on, but in this case the mouse event gets generated inside QWidget.
    Are my considerations wrong? Where is the mousevent generated?

    Any suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overriding QWidget::event does not work!

    If that's indeed the case then my guess is that you're simply handling the event for the wrong widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2012
    Posts
    18
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Overriding QWidget::event does not work!

    I am pretty sure to handle the event for the correct widget. The example application exists of a QMainWindow. Inside this QMainWindow lives my Scribblearea.
    For this QWidget i would like to suppress the QMouseEvent. There should be no propagation, because the ScribbleArea should eat the TouchEvent by returning true.

    This is indeed, the way i understood QTs event processing. But it simply does not work. Or maybe i am getting something wrong?

    If someone could do me a favour and try out my piece of code on his or her machine, i would be greatfull.
    Simply copy and paste my code in the ScribbleArea and try yourself.

    Thanks in advance

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overriding QWidget::event does not work!

    Did you verify that your code indeed gets executed at all?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2012
    Posts
    18
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Overriding QWidget::event does not work!

    Hey,

    when setting breakpoints, whether in the QTouchEvent case or in the QMouseEvent case, both are triggered.

    Thats really strange, when simulating the same with QTabletEvents, it works as expected: When i do not accept the QTabletEvent, i also got a QMouseEvent (as expected).
    When accepting the QTabletEvent i do not get a QMouseEvent (as expected).

    Exactly the behaviour, i would like to have for QTouchEvents.

    What else can be done?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overriding QWidget::event does not work!

    Simplify the example even more. Get rid of the main window so that the scribble area is the only widget in the application. See if that changes anything. You can also try stepping through the code once the brekpoint in your event() implementation fires to see what happens later after event() returns.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Overriding QWidget::event does not work!

    I agree with Wysota - other widgets may be propagating the events up to your scribble widget, with the result that it appears as if the event is coming from the scribble area when it is not. Simplify to the point where the only widget present is the scribble widget and see if there is a difference.

  8. #8
    Join Date
    Nov 2012
    Posts
    18
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Overriding QWidget::event does not work!

    Hey, i tried that.

    I removed the ScribbleArea widget. Since the QMainWindow is also a widget, i moved the code above from the ScribbleArea to the QMainWindow.
    Same behaviour here. Note the QMainWindow, does not override one of the specific eventhandlers.
    Here is the headefile of the QMainWindow. It simply implements the event member function.

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QList>
    5. #include <QMainWindow>
    6.  
    7. //! [0]
    8. class MainWindow : public QMainWindow
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. MainWindow();
    14.  
    15. protected:
    16. bool event(QEvent*)
    17. private:
    18.  
    19. };
    20. //! [0]
    21.  
    22. #endif
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overriding QWidget::event does not work!

    QMainWindow is really a bunch of widgets. It's better to remove it and leave the scribble widget in your app for testing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Nov 2012
    Posts
    18
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Overriding QWidget::event does not work!

    Hey,

    when ever i had a little free time in the last couple of days, i tried to work on this.

    I removed the QMainWindow, there is only a QWidget in my application. I studied the code of QWidget again and i am sure the QMouseEvent is generated inside QWidget, as i already showed.
    That is also documented in the DOCs of QT under:
    Event Delivery and Propagation
    By default, QWidget::event() translates the first non-primary touch point in a QTouchEvent into a QMouseEvent.
    http://qt-project.org/doc/qt-4.8/qtouchevent.html

    However, i accept all TouchEvent, return true, but the MouseEvent still is getting fired.

    There is nothing inside my widget, except the reimplementation of event(QEvent*) member function. Nothing else.

    Thus, the only possible answer left is, that the MouseEvent must come from anywhere else?

    Any ideas on this?

    This is driving me crazy.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overriding QWidget::event does not work!

    Take a debugger and step through the code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.