diff --git a/lcl/interfaces/qt/qtobject.inc b/lcl/interfaces/qt/qtobject.inc index 4e602759c8..4ceb5751ac 100644 --- a/lcl/interfaces/qt/qtobject.inc +++ b/lcl/interfaces/qt/qtobject.inc @@ -622,7 +622,7 @@ end; function TQtWidgetSet.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; var AObject: TQtObject; - W: TQtMainWindow; + W: TQtWidget; LCLEvent: QLCLMessageEventH; ASequence: QKeySequenceH; AKey: WideString; @@ -809,8 +809,9 @@ begin // eat next appdeactivate & appactivate since we are changing form // flags ! if (StayOnTopList <> nil) then - W := TQtMainWindow(HWNDFromWidgetH(QApplication_activeWindow())) - else + begin + W := TQtWidget(GetActiveWindow); + end else W := nil; Application.IntfAppActivate; QtRestoreStayOnTop; diff --git a/lcl/interfaces/qt/qtwinapi.inc b/lcl/interfaces/qt/qtwinapi.inc index 7fd0c28b33..7d8e338dc6 100644 --- a/lcl/interfaces/qt/qtwinapi.inc +++ b/lcl/interfaces/qt/qtwinapi.inc @@ -2498,12 +2498,17 @@ var begin Result := 0; Widget := QApplication_activeWindow; - if Widget <> nil then + {return modal if activeWindow is nil issue #33409} + if Widget = nil then + Widget := QApplication_activeModalWidget; + if Widget = nil then + Widget := QApplication_activePopupWidget; + if Assigned(Widget) then begin W := QtObjectFromWidgetH(Widget); - if W <> nil then + if Assigned(W) and IsValidHandle(HWND(W)) then begin - if TQtMainWindow(W).MDIAreaHandle <> nil then + if (TQtWidget(W) is TQtMainWindow) and (TQtMainWindow(W).MDIAreaHandle <> nil) then begin Area := QMdiAreaH(TQtMainWindow(W).MDIAreaHandle.Widget); SubW := QtObjectFromWidgetH(QMdiArea_activeSubWindow(Area)); diff --git a/lcl/interfaces/qt5/qtobject.inc b/lcl/interfaces/qt5/qtobject.inc index 2381ec23f7..f611147136 100644 --- a/lcl/interfaces/qt5/qtobject.inc +++ b/lcl/interfaces/qt5/qtobject.inc @@ -574,7 +574,7 @@ end; function TQtWidgetSet.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; var AObject: TQtObject; - W: TQtMainWindow; + W: TQtWidget; LCLEvent: QLCLMessageEventH; ASequence: QKeySequenceH; AKey: WideString; @@ -764,7 +764,7 @@ begin // eat next appdeactivate & appactivate since we are changing form // flags ! if (StayOnTopList <> nil) then - W := TQtMainWindow(HWNDFromWidgetH(QApplication_activeWindow())) + W := TQtWidget(GetActiveWindow) else W := nil; Application.IntfAppActivate; diff --git a/lcl/interfaces/qt5/qtwinapi.inc b/lcl/interfaces/qt5/qtwinapi.inc index 1a00b89dc0..ab99165e36 100644 --- a/lcl/interfaces/qt5/qtwinapi.inc +++ b/lcl/interfaces/qt5/qtwinapi.inc @@ -2445,12 +2445,17 @@ var begin Result := 0; Widget := QApplication_activeWindow; + {return modal if activeWindow is nil issue #33409} + if Widget = nil then + Widget := QApplication_activeModalWidget; + if Widget = nil then + Widget := QApplication_activePopupWidget; if Widget <> nil then begin W := QtObjectFromWidgetH(Widget); - if W <> nil then + if Assigned(W) and IsValidHandle(HWND(W)) then begin - if TQtMainWindow(W).MDIAreaHandle <> nil then + if (TQtWidget(W) is TQtMainWindow) and Assigned(TQtMainWindow(W).MDIAreaHandle) then begin Area := QMdiAreaH(TQtMainWindow(W).MDIAreaHandle.Widget); SubW := QtObjectFromWidgetH(QMdiArea_activeSubWindow(Area)); @@ -6007,6 +6012,8 @@ var W: QWidgetH; begin {$IFDEF HASX11} + {$note this should return current system active window, not + application one, if our app isn''t active.} if WindowManagerName = 'metacity' then W := X11GetActivewindow else