From 48fe9db698764e81edc9117b6db21244e8798f51 Mon Sep 17 00:00:00 2001 From: rich2014 Date: Thu, 27 Apr 2023 22:16:50 +0800 Subject: [PATCH] Qt6: Adjust Form's MainMenu strategy at Design Time, to be consistent with other Interfaces --- lcl/interfaces/qt6/qtwidgets.pas | 34 ++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lcl/interfaces/qt6/qtwidgets.pas b/lcl/interfaces/qt6/qtwidgets.pas index fc1619c6de..b7d54013e4 100644 --- a/lcl/interfaces/qt6/qtwidgets.pas +++ b/lcl/interfaces/qt6/qtwidgets.pas @@ -1669,7 +1669,9 @@ type constructor Create(const AParent: QWidgetH); overload; public {$IFNDEF DARWIN} + function GetDesignState: Integer; function IsDesigning: Boolean; + function ShouldShowMenuBar: Boolean; {$ENDIF} function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override; function addMenu(AMenu: QMenuH): QActionH; @@ -7338,6 +7340,7 @@ end; function TQtMainWindow.MenuBarNeeded: TQtMenuBar; var AParent: QWidgetH; + designState: Integer; begin if not Assigned(FMenuBar) then begin @@ -7353,10 +7356,12 @@ begin if not (csDesigning in LCLObject.ComponentState) then FMenuBar.FIsApplicationMainMenu := {$IFDEF DARWIN}False{$ELSE}IsMainForm{$ENDIF} else + begin {$IFNDEF DARWIN} - FMenuBar.setProperty(FMenuBar.Widget,'lcldesignmenubar',1) + designState := IfThen( Assigned(LCLObject.Parent), 1, 2 ); + FMenuBar.setProperty(FMenuBar.Widget,'lcldesignmenubar',designState); {$ENDIF} - ; + end; {$IFDEF DARWIN} if (csDesigning in LCLObject.ComponentState) or not IsMainForm then @@ -7453,7 +7458,7 @@ end; // currently only handles the adjustments that MainMenu needs to make function TQtMainWindow.GetClientRectFix(): TSize; begin - if Assigned(FMenuBar) and (not IsMdiChild) then + if Assigned(FMenuBar) and FMenuBar.FVisible and (not IsMdiChild) then begin FMenuBar.sizeHint(@Result); if Result.Height<10 then Result.Height:=0; @@ -16585,21 +16590,30 @@ end; {$IFNDEF DARWIN} function TQtMenuBar.IsDesigning: Boolean; +begin + Result := GetDesignState() <> 0; +end; + +function TQtMenuBar.ShouldShowMenuBar: Boolean; +begin + Result := GetDesignState() <> 2; +end; + +function TQtMenuBar.GetDesignState: Integer; var V: QVariantH; B: Boolean; begin - Result := (Widget <> nil); - if not Result then - exit(False); + Result := 0; + if Widget = nil then + exit; - Result := False; v := QVariant_create(); try B := False; QObject_property(Widget, v, 'lcldesignmenubar'); if QVariant_isValid(v) and not QVariant_isNull(v) then - Result := QVariant_toInt(V, @B) = 1; + Result := QVariant_toInt(V, @B); finally QVariant_destroy(v); end; @@ -16685,7 +16699,7 @@ end; function TQtMenuBar.addMenu(AMenu: QMenuH): QActionH; begin - if not FVisible then + if ShouldShowMenuBar and (not FVisible) then begin FVisible := True; setVisible(FVisible); @@ -16702,7 +16716,7 @@ var seq: QKeySequenceH; WStr: WideString; begin - if not FVisible then + if ShouldShowMenuBar and (not FVisible) then begin FVisible := True; setVisible(FVisible);