View Full Version : Qt5 Mac - QScrollArea viewport not recieving appropriate Enter/Leave Events

17th January 2013, 20:11
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.

#include <QApplication.h>
#include <QGLWidget.h>
#include <QAbstractScrollArea.h>
#include <QMouseEvent.h>

int main(int argc, char *argv[]) {

QApplication app(argc, argv);

Qt5DebugScrollArea debugWidget;

return app.exec();

class Qt5DebugScrollArea : public QAbstractScrollArea {
Qt5DebugScrollArea() {
resize(500, 500);


virtual bool viewportEvent(QEvent *event) {
if (event->type() == QEvent::Leave)
std::cout << "Viewport Leave Event" << std::endl;
else if (event->type() == QEvent::Enter)
std::cout << "Viewport Enter Event" << std::endl;
return QAbstractScrollArea::viewportEvent(event);

virtual void mouseMoveEvent(QMouseEvent *event) {
std::cout << "MouseEvent Pos= " << event->pos().x() << ", " << event->pos().y() << std::endl;

virtual void leaveEvent(QEvent *event) {
std::cout << "Leave Event" << std::endl;

virtual void enterEvent(QEvent *event) {
std::cout << "Enter Event" << std::endl;

void makeViewport() {
mViewportWidget = new QGLWidget();

QGLWidget *mViewportWidget;