We have noticed that mouse events for widgets in a QAbstractScrollArea have been, at best, bizarre since upgrading to Qt5. The more significant issues seem to only occur on the Mac but there are slight issues on our PC build as well.

When we have a standard widget in a QAbstractScrollArea it only receives Enter/Leave events when we move the mouse slowly enough off of the viewport that MouseMove events are picked up by some other widget in the window. For example if we slowly move off of the viewport to the title bar we get a Leave event. If we move the mouse very quickly off of the viewport and don't hit MouseMoves on any other widget in the window we never receive a Leave event.

When we have a QGLWidget in a QAbstractScrollArea it never receives Enter/Leave events at all. Below is a simple example of the problem. Basically once we have clicked into the viewport any mouse motion, be it over the viewport, over the non-client area of the window, or anywhere else on my screen where there is no Qt window at all translates to a MouseMove event. It seems like the QGLWidget or scroll widget is grabbing the mouse and not letting go of it. I should also note that other checks like QWidget::underMouse() always reports true regardless of where the mouse is, we never get NonClientAreaMouse events, etc.

The following code is pretty straightforward - is there a reason we should be experiencing the described issue? Again note this only occurs on Qt5 Mac builds.

Thanks for any advice/information.

Qt Code:
  1. #include <QApplication.h>
  2. #include <QGLWidget.h>
  3. #include <QAbstractScrollArea.h>
  4. #include <QMouseEvent.h>
  5.  
  6. int main(int argc, char *argv[]) {
  7.  
  8. QApplication app(argc, argv);
  9.  
  10. Qt5DebugScrollArea debugWidget;
  11. debugWidget.show();
  12.  
  13. return app.exec();
  14. }
  15.  
  16. class Qt5DebugScrollArea : public QAbstractScrollArea {
  17. public:
  18. Qt5DebugScrollArea() {
  19. makeViewport();
  20. resize(500, 500);
  21. setMouseTracking(true);
  22. viewport()->setMouseTracking(true);
  23. mViewportWidget->setMouseTracking(true);
  24. }
  25.  
  26. protected:
  27.  
  28. virtual bool viewportEvent(QEvent *event) {
  29. if (event->type() == QEvent::Leave)
  30. std::cout << "Viewport Leave Event" << std::endl;
  31. else if (event->type() == QEvent::Enter)
  32. std::cout << "Viewport Enter Event" << std::endl;
  33. return QAbstractScrollArea::viewportEvent(event);
  34. }
  35.  
  36. virtual void mouseMoveEvent(QMouseEvent *event) {
  37. std::cout << "MouseEvent Pos= " << event->pos().x() << ", " << event->pos().y() << std::endl;
  38. QAbstractScrollArea::mouseMoveEvent(event);
  39. }
  40.  
  41. virtual void leaveEvent(QEvent *event) {
  42. std::cout << "Leave Event" << std::endl;
  43. QAbstractScrollArea::leaveEvent(event);
  44. }
  45.  
  46. virtual void enterEvent(QEvent *event) {
  47. std::cout << "Enter Event" << std::endl;
  48. QAbstractScrollArea::enterEvent(event);
  49. }
  50.  
  51. private:
  52. void makeViewport() {
  53. mViewportWidget = new QGLWidget();
  54. mViewportWidget->setParent(viewport());
  55. }
  56.  
  57. private:
  58. QGLWidget *mViewportWidget;
  59.  
  60. };
To copy to clipboard, switch view to plain text mode