diff --git a/lcl/interfaces/qt/qtwidgets.pas b/lcl/interfaces/qt/qtwidgets.pas index f6db0dfe05..3dcae21ef8 100644 --- a/lcl/interfaces/qt/qtwidgets.pas +++ b/lcl/interfaces/qt/qtwidgets.pas @@ -219,6 +219,7 @@ type function getHeight: Integer; function getUpdatesEnabled: Boolean; function getWidth: Integer; + function getWindow: TQtWidget; function getWindowState: QtWindowStates; procedure grabMouse; virtual; function hasFocus: Boolean; virtual; @@ -491,6 +492,7 @@ type TQtMainWindow = class(TQtWidget) private + FBlocked: Boolean; LayoutWidget: QBoxLayoutH; FCWEventHook: QObject_hookH; FShowOnTaskBar: Boolean; @@ -524,6 +526,7 @@ type procedure slotWindowStateChange; cdecl; procedure setShowInTaskBar(AValue: Boolean); procedure setPopupParent(APopupMode: TPopupMode; NewParent: QWidgetH); + property Blocked: Boolean read FBlocked write FBlocked; property ShowOnTaskBar: Boolean read FShowOnTaskBar; public procedure AttachEvents; override; @@ -3498,6 +3501,16 @@ begin Result := QWidget_width(Widget); end; +function TQtWidget.getWindow: TQtWidget; +var + W: QWidgetH; +begin + Result := nil; + W := QWidget_window(Widget); + if W <> nil then + Result := TQtWidget(HwndFromWidgetH(W)); +end; + function TQtWidget.getWindowState: QtWindowStates; begin Result := QWidget_windowState(Widget); @@ -4581,6 +4594,7 @@ begin {$ifdef VerboseQt} WriteLn('TQtMainWindow.CreateWidget Name: ', LCLObject.Name); {$endif} + FBlocked := False; FShowOnTaskBar := False; QtFormBorderStyle := Ord(bsSizeable); QtFormStyle := Ord(fsNormal); @@ -4821,6 +4835,8 @@ begin BeginEventProcessing; case QEvent_type(Event) of + QEventWindowUnblocked: Blocked := False; + QEventWindowBlocked: Blocked := True; QEventWindowActivate: SlotActivateWindow(True); QEventWindowDeactivate: SlotActivateWindow(False); QEventShowToParent: diff --git a/lcl/interfaces/qt/qtwinapi.inc b/lcl/interfaces/qt/qtwinapi.inc index c854ff864f..39ae8ba37d 100644 --- a/lcl/interfaces/qt/qtwinapi.inc +++ b/lcl/interfaces/qt/qtwinapi.inc @@ -4881,6 +4881,8 @@ end; ------------------------------------------------------------------------------} function TQtWidgetSet.SetFocus(hWnd: HWND): HWND; +var + W: TQtWidget; begin Result := 0; if hwnd<>0 then @@ -4889,6 +4891,10 @@ begin WriteLn('********* TQtWidgetSet.SetFocus INIT focusing ', TQtWidget(hwnd).lclobject.name); {$endif} Result := GetFocus; + W := TQtWidget(HWND).getWindow; + if (W <> nil) and not W.IsActiveWindow and + not TQtMainWindow(W).Blocked then + W.Activate; TQtWidget(hWnd).setFocus; {$ifdef VerboseFocus} DebugLn('********* TQtWidgetSet.SetFocus END was %x now is %x',[result,hwnd]);