diff --git a/include/wx/qt/window.h b/include/wx/qt/window.h index b0f55efb33..adcaf6b48d 100644 --- a/include/wx/qt/window.h +++ b/include/wx/qt/window.h @@ -167,7 +167,7 @@ public: static void QtStoreWindowPointer( QWidget *widget, const wxWindowQt *window ); static wxWindowQt *QtRetrieveWindowPointer( const QWidget *widget ); - static void QtSendSetCursorEvent(wxWindowQt* win, wxPoint posClient); + static void QtSendSetCursorEvent(wxWindowQt* win, const wxPoint& posClient); #if wxUSE_ACCEL virtual void QtHandleShortcut ( int command ); diff --git a/src/qt/window.cpp b/src/qt/window.cpp index 16974f8b2e..085fbcf99b 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -271,27 +271,33 @@ static const char WINDOW_POINTER_PROPERTY_NAME[] = "wxWindowPointer"; } /* static */ -void wxWindowQt::QtSendSetCursorEvent(wxWindowQt* win, wxPoint posScreen) +void wxWindowQt::QtSendSetCursorEvent(wxWindowQt* win, const wxPoint& posClient) { - wxWindowQt* w = win; - for ( ;; ) - { - const wxPoint posClient = w->ScreenToClient(posScreen); - wxSetCursorEvent event(posClient.x, posClient.y); - event.SetEventObject(w); + const wxRect rect(win->GetClientAreaOrigin(), win->GetClientSize()); - const bool processedEvtSetCursor = w->ProcessWindowEvent(event); + if ( rect.Contains(posClient) ) + { + wxSetCursorEvent event( posClient.x , posClient.y ); + event.SetId(win->GetId()); + event.SetEventObject(win); + + const bool processedEvtSetCursor = win->HandleWindowEvent(event); if ( processedEvtSetCursor && event.HasCursor() ) { win->SetCursor(event.GetCursor()); - return; } + else + { + // Notice that GetCursor() can return an invalid cursor even if the window already + // has a valid cursor set at the Qt level. Don't override it if this is the case. + const bool hasCursor = win->GetHandle()->testAttribute(Qt::WA_SetCursor); - w = w->GetParent(); - if ( w == nullptr ) - break; + if ( !hasCursor || (!wxIsBusy() && !win->GetParent()) ) + { + win->SetCursor( *wxSTANDARD_CURSOR ); + } + } } - win->SetCursor(wxCursor(wxCURSOR_ARROW)); } static wxWindowQt *s_capturedWindow = nullptr; @@ -1686,7 +1692,7 @@ bool wxWindowQt::QtHandleMouseEvent ( QWidget *handler, QMouseEvent *event ) ProcessWindowEvent( e ); } - QtSendSetCursorEvent(this, wxQtConvertPoint( event->globalPos())); + QtSendSetCursorEvent(this, mousePos); } m_mouseInside = mouseInside;