View Issue Details

IDProjectCategoryView StatusLast Update
0037576LazarusWidgetsetpublic2021-03-27 22:41
ReporterJuha Manninen Assigned ToZeljan Rikalo  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformAMD RyzenOSLinux 64-bit 
Product Version2.1 (SVN) 
Summary0037576: With QT5 anchored controls inside a GroupBox are placed wrongly when the GroupBox has no caption
DescriptionFor example in the string property editor TStringsPropEditorFrm (unit StringsPropEditDlg) StatusLabel is anchored to its container GroupBox's bottom. The label's bottom edge should be 6 pix (border space) above the GroupBox bottom edge.
It is so with GTK2 and other widgetsets.
With QT5 it goes lower, mostly outside the GroupBox. It happens both in design time and in run time. I didn't test with QT4.
I added a temporary caption to TStringsPropEditorFrm's TextGroupBox in r63750.

I attach a demo project. In the main form you can replicate the error by removing caption from the GroupBox.
There is also a stripped version of TStringsPropEditorFrm. I reduced the cause of error with it.
This form can be opened with a button on the main form.

Manjaro has recent versions or QT libs. This is from ldconfig -p :
  libQt5Core.so.5 (libc6,x86-64, OS ABI: Linux 3.17.0) => /usr/lib/libQt5Core.so.5
  libQt5Core.so (libc6,x86-64, OS ABI: Linux 3.17.0) => /usr/lib/libQt5Core.so
How to get more precise versions?
Additional InformationThere is also another problem with anchors. The anchor editor itself starts to behave wrong after using it for a while. The anchor side buttons cannot be switched, or a wrong button gets selected when you click. The problem goes away after restarting Lazarus. Something gets corrupt somewhere.
I don't remember seeing that with LCL-GTK2.
TagsNo tags attached.
Fixed in Revision64857
LazTarget-
WidgetsetQT5
Attached Files

Relationships

related to 0032186 resolvedZeljan Rikalo Toggle buttons in anchor editor are not responding with Qt5 
related to 0032346 closedZeljan Rikalo TGroupBox clips controls at bottom when it is Autosize=TRUE 
related to 0023642 closedZeljan Rikalo Qt: groupBox without caption should reduce top margin 
related to 0028155 closedZeljan Rikalo Invisible TLabel on TGroupBox 

Activities

Juha Manninen

2020-08-16 10:05

developer   ~0124914

A demo project.
project1.zip (109,300 bytes)

Zeljan Rikalo

2020-09-21 13:02

developer   ~0125708

Please: I need Qt theme info. You can test your app with eg ./myapp -style windows to check if it works with such simple theme.

Juha Manninen

2020-09-21 16:03

developer   ~0125719

Last edited: 2020-09-21 17:09

View 2 revisions

@Zeljko, the -style param has no effect for this issue.
Do you mean you cannot reproduce the bug?
You don't even need to run the demo app. Just remove the GroupBox Caption at design-time, In Lazarus IDE built with QT5, and you see the problem.

Zeljan Rikalo

2020-12-22 21:50

developer   ~0127770

Indeed it's strange behaviour, I'll attach possible patch so you can test. Also, before applying I must test windows and mac to see if that makes problem , or even if there's same bug at all.

Zeljan Rikalo

2020-12-22 21:54

developer   ~0127771

Here is possible patch for this issue. Tested on Fedora 31, 64bit, Qt 5.13.2
qt5_issue_37576.diff (1,164 bytes)   
Index: lcl/interfaces/qt5/qtwidgets.pas
===================================================================
--- lcl/interfaces/qt5/qtwidgets.pas	(revision 64264)
+++ lcl/interfaces/qt5/qtwidgets.pas	(working copy)
@@ -8125,12 +8125,13 @@
 begin
   if ALayout = nil then
     exit;
+
   QWidget_getContentsMargins(AWidget,@LeftMargin, @TopMargin, @RightMargin, @BottomMargin);
 
   {if contentsMargins TopMargin is huge then we must rethink about TopMargin
    size (eg.oxygen theme have 32 top margin while plastique have 19
    with same font height) }
-  {$IFDEF HASX11}
+  {$IFDEF HASX111}
   Font := QWidget_font(AWidget);
   FontMetrics := QFontMetrics_create(Font);
   try
@@ -8152,9 +8153,12 @@
     end;
   end;
   {$ENDIF}
+
   {if there's no text set margin to bottom margin size. issue #23642}
-  if getText = '' then
-    TopMargin := BottomMargin;
+  if (getText = '') and (QtWidgetSet.StyleName <> 'fusion') then
+    TopMargin := 0;
+
+  QWidget_setContentsMargins(AWidget, LeftMargin, TopMargin, RightMargin, BottomMargin);
   QLayout_setContentsMargins(ALayout, LeftMargin, TopMargin, RightMargin, BottomMargin);
   QLayout_invalidate(ALayout);
 
qt5_issue_37576.diff (1,164 bytes)   

Juha Manninen

2020-12-23 00:28

developer   ~0127772

Indeed the patch solves the problem!
It was not even close to the code I studied regarding this issue. Proves how little I understand of the LCL bindings code.

Zeljan Rikalo

2020-12-23 09:56

developer   ~0127775

@Juha, maybe it solves problem for anchored controls inside TGroupBox, but as I can remember when I rebuild lazarus with such changes all TGroupBoxes in lazarus options have some extra spacing below caption. Not sure, please look at that detail , also TCheckGroup and TRadioGroup should be tested.

Juha Manninen

2020-12-23 19:06

developer   ~0127783

True, the patch causes a small barely noticeable extra space below a TGroupBoxes caption.

Zeljan Rikalo

2020-12-24 15:47

developer   ~0127790

I'll try to rewrite complete layout of TGroupBox for qt5, won't touch qt4

Zeljan Rikalo

2021-03-02 13:55

developer   ~0129315

Please test with attached patch. It works ok on linux (Linux Mint 20, Qt-5.12, 64bit, fpc-3.2.0)
qt5_issue37576.diff (2,479 bytes)   
Index: lcl/interfaces/qt5/qtwidgets.pas
===================================================================
--- lcl/interfaces/qt5/qtwidgets.pas	(revision 64716)
+++ lcl/interfaces/qt5/qtwidgets.pas	(working copy)
@@ -8115,53 +8115,30 @@
   LeftMargin: Integer;
   TopMargin: Integer;
   RightMargin: Integer;
-  BottomMargin: Integer;
-  {$IFDEF HASX11}
-  Font: QFontH;
-  FontMetrics: QFontMetricsH;
-  FontHeight: Integer;
-  {$ENDIF}
+  BottomMargin, AStyleMetric: Integer;
 begin
   if ALayout = nil then
     exit;
   QWidget_getContentsMargins(AWidget,@LeftMargin, @TopMargin, @RightMargin, @BottomMargin);
 
-  {if contentsMargins TopMargin is huge then we must rethink about TopMargin
-   size (eg.oxygen theme have 32 top margin while plastique have 19
-   with same font height) }
-  {$IFDEF HASX11}
-  Font := QWidget_font(AWidget);
-  FontMetrics := QFontMetrics_create(Font);
-  try
-    FontHeight := QFontMetrics_height(FontMetrics);
-  finally
-    QFontMetrics_destroy(FontMetrics);
-  end;
-  {currently applies only to wrong TopMargin calculation (eg.gtk style).}
-  if (TopMargin - FontHeight < 2) then
-    TopMargin := FontHeight + 2 // top & bottom +1px
-  else {currently applies only to oxygen & nitrogen theme.}
-  if ((TopMargin - BottomMargin - 2) > FontHeight) then
-  begin
-    {do not touch fusion style !}
-    if QtWidgetSet.StyleName <> 'fusion' then
-    begin
-      TopMargin := TopMargin - BottomMargin - 3;
-      BottomMargin := 0;
-    end;
-  end;
-  {$ENDIF}
-  {if there's no text set margin to bottom margin size. issue #23642}
-  if getText = '' then
+  AStyleMetric := QStyle_pixelMetric(QApplication_style(), QStyleSE_DockWidgetTitleBarText, nil, Widget);
+
+  {issue #37576}
+  {if (AStyle = 'fusion') or (AStyle = 'gtk2') or
+    (AStyle = 'qt5ct-style') then}
+  if AStyleMetric = 0 then
+  else
+  if (getText = '') then
     TopMargin := BottomMargin;
+
   QLayout_setContentsMargins(ALayout, LeftMargin, TopMargin, RightMargin, BottomMargin);
   QLayout_invalidate(ALayout);
 
   if (LCLObject <> nil) and testAttribute(QtWA_Mapped) then
   begin
-    {.$IFDEF VerboseQtResize}
+    {$IFDEF VerboseQtResize}
     DebugLn('TQtGroupBox.setLayoutThemeMargins: ',dbgsName(LCLObject),' casp: ',dbgs(caspComputingBounds in LCLObject.AutoSizePhases),' mapped ',dbgs(testAttribute(QtWA_Mapped)));
-    {.$ENDIF}
+    {$ENDIF}
     LCLObject.DoAdjustClientRectChange(False);
     LCLObject.InvalidateClientRectCache(True);
   end;
qt5_issue37576.diff (2,479 bytes)   

Zeljan Rikalo

2021-03-02 13:55

developer   ~0129316

Anyone can test with attached patch ? Also, if someone can test win10 and mac

Juha Manninen

2021-03-10 12:43

developer   ~0129544

Last edited: 2021-03-10 17:33

View 3 revisions

The patch really fixes the issue. Great!
[Edit] No, it did not solve the related Anchor Editor issue 0032186. It happens occasionally as before.

Zeljan Rikalo

2021-03-11 13:06

developer   ~0129569

@Juha, I already mentioned that I should fix mouse press problem, this patch is only for positioning. I cannot reproduce problem with simple form + TGroupBox + TSpeedButton inside such control, maybe it reacts only when TGraphicControl is anchored, so must create some good example....I don't want to debug whole lazarus because of such bug.

Zeljan Rikalo

2021-03-12 14:53

developer   ~0129604

Complete patch which fixes mouse press/release problems and also visual problems.
qt5_issue37576_2.diff (2,899 bytes)   
Index: lcl/interfaces/qt5/qtwidgets.pas
===================================================================
--- lcl/interfaces/qt5/qtwidgets.pas	(revision 64743)
+++ lcl/interfaces/qt5/qtwidgets.pas	(working copy)
@@ -8115,53 +8115,30 @@
   LeftMargin: Integer;
   TopMargin: Integer;
   RightMargin: Integer;
-  BottomMargin: Integer;
-  {$IFDEF HASX11}
-  Font: QFontH;
-  FontMetrics: QFontMetricsH;
-  FontHeight: Integer;
-  {$ENDIF}
+  BottomMargin, AStyleMetric: Integer;
 begin
   if ALayout = nil then
     exit;
   QWidget_getContentsMargins(AWidget,@LeftMargin, @TopMargin, @RightMargin, @BottomMargin);
 
-  {if contentsMargins TopMargin is huge then we must rethink about TopMargin
-   size (eg.oxygen theme have 32 top margin while plastique have 19
-   with same font height) }
-  {$IFDEF HASX11}
-  Font := QWidget_font(AWidget);
-  FontMetrics := QFontMetrics_create(Font);
-  try
-    FontHeight := QFontMetrics_height(FontMetrics);
-  finally
-    QFontMetrics_destroy(FontMetrics);
-  end;
-  {currently applies only to wrong TopMargin calculation (eg.gtk style).}
-  if (TopMargin - FontHeight < 2) then
-    TopMargin := FontHeight + 2 // top & bottom +1px
-  else {currently applies only to oxygen & nitrogen theme.}
-  if ((TopMargin - BottomMargin - 2) > FontHeight) then
-  begin
-    {do not touch fusion style !}
-    if QtWidgetSet.StyleName <> 'fusion' then
-    begin
-      TopMargin := TopMargin - BottomMargin - 3;
-      BottomMargin := 0;
-    end;
-  end;
-  {$ENDIF}
-  {if there's no text set margin to bottom margin size. issue #23642}
-  if getText = '' then
+  AStyleMetric := QStyle_pixelMetric(QApplication_style(), QStyleSE_DockWidgetTitleBarText, nil, Widget);
+
+  {issue #37576}
+  {if (AStyle = 'fusion') or (AStyle = 'gtk2') or
+    (AStyle = 'qt5ct-style') then}
+  if AStyleMetric = 0 then
+  else
+  if (getText = '') then
     TopMargin := BottomMargin;
+
   QLayout_setContentsMargins(ALayout, LeftMargin, TopMargin, RightMargin, BottomMargin);
   QLayout_invalidate(ALayout);
 
   if (LCLObject <> nil) and testAttribute(QtWA_Mapped) then
   begin
-    {.$IFDEF VerboseQtResize}
+    {$IFDEF VerboseQtResize}
     DebugLn('TQtGroupBox.setLayoutThemeMargins: ',dbgsName(LCLObject),' casp: ',dbgs(caspComputingBounds in LCLObject.AutoSizePhases),' mapped ',dbgs(testAttribute(QtWA_Mapped)));
-    {.$ENDIF}
+    {$ENDIF}
     LCLObject.DoAdjustClientRectChange(False);
     LCLObject.InvalidateClientRectCache(True);
   end;
@@ -8378,7 +8355,15 @@
   L, T, R, B: Integer;
   ASize: TSize;
 begin
-  QWidget_getContentsMargins(Widget,@L, @T, @R, @B);
+  if WithThemeSpace then
+    QWidget_getContentsMargins(Widget,@L, @T, @R, @B)
+  else
+  begin
+    L := 0;
+    T := 0;
+    R := 0;
+    B := 0;
+  end;
   QGroupBox_minimumSizeHint(QGroupBoxH(Widget), @ASize);
   PreferredWidth := ASize.cx + L + R;
   PreferredHeight := ASize.cy + B + T;
qt5_issue37576_2.diff (2,899 bytes)   

Zeljan Rikalo

2021-03-12 14:54

developer   ~0129605

@Juha, please test with qt_issue37576_2.diff patch. Now mouse click is fixed also. This is complete patch, so revert previous one and apply this one. I've just tested on linux with lazarus r64790

Juha Manninen

2021-03-15 09:24

developer   ~0129678

Sorry for the delay.
It works very well in my tests. I could not reproduce the Anchor Editor bug any more either.

Zeljan Rikalo

2021-03-15 11:34

developer   ~0129683

@Juha: THANKS !

Zeljan Rikalo

2021-03-22 14:13

developer   ~0129829

Please test and close if ok.

Issue History

Date Modified Username Field Change
2020-08-15 18:20 Juha Manninen New Issue
2020-08-15 18:20 Juha Manninen Status new => assigned
2020-08-15 18:20 Juha Manninen Assigned To => Zeljan Rikalo
2020-08-16 10:04 Juha Manninen Summary With QT5 anchored controls are sometimes placed wrongly => With QT5 anchored controls inside a GroupBox are placed wrongly when the GroupBox has no caption
2020-08-16 10:04 Juha Manninen Description Updated View Revisions
2020-08-16 10:04 Juha Manninen Additional Information Updated View Revisions
2020-08-16 10:04 Juha Manninen LazTarget => -
2020-08-16 10:04 Juha Manninen Widgetset QT5 => QT5
2020-08-16 10:05 Juha Manninen Note Added: 0124914
2020-08-16 10:05 Juha Manninen File Added: project1.zip
2020-08-16 10:15 Juha Manninen Relationship added related to 0032186
2020-08-16 10:15 Juha Manninen Relationship added related to 0032346
2020-08-16 10:20 Juha Manninen OS => Linux 64-bit
2020-08-16 10:20 Juha Manninen OS Version => Manjaro
2020-08-16 10:20 Juha Manninen Platform => AMD Ryzen
2020-08-16 10:20 Juha Manninen Description Updated View Revisions
2020-08-16 10:20 Juha Manninen Widgetset QT5 => QT5
2020-09-21 13:02 Zeljan Rikalo Status assigned => feedback
2020-09-21 13:02 Zeljan Rikalo Note Added: 0125708
2020-09-21 16:03 Juha Manninen Note Added: 0125719
2020-09-21 16:03 Juha Manninen Status feedback => assigned
2020-09-21 17:09 Juha Manninen Note Edited: 0125719 View Revisions
2020-12-22 20:45 Zeljan Rikalo Relationship added related to 0023642
2020-12-22 21:02 Zeljan Rikalo Relationship added related to 0028155
2020-12-22 21:50 Zeljan Rikalo Status assigned => confirmed
2020-12-22 21:50 Zeljan Rikalo Note Added: 0127770
2020-12-22 21:54 Zeljan Rikalo Note Added: 0127771
2020-12-22 21:54 Zeljan Rikalo File Added: qt5_issue_37576.diff
2020-12-23 00:28 Juha Manninen Note Added: 0127772
2020-12-23 09:56 Zeljan Rikalo Note Added: 0127775
2020-12-23 19:06 Juha Manninen Note Added: 0127783
2020-12-24 15:47 Zeljan Rikalo Note Added: 0127790
2021-03-02 13:55 Zeljan Rikalo Note Added: 0129315
2021-03-02 13:55 Zeljan Rikalo File Added: qt5_issue37576.diff
2021-03-02 13:55 Zeljan Rikalo Status confirmed => feedback
2021-03-02 13:55 Zeljan Rikalo Note Added: 0129316
2021-03-10 12:43 Juha Manninen Note Added: 0129544
2021-03-10 12:43 Juha Manninen Status feedback => assigned
2021-03-10 15:37 Juha Manninen Note Edited: 0129544 View Revisions
2021-03-10 17:33 Juha Manninen Note Edited: 0129544 View Revisions
2021-03-11 13:06 Zeljan Rikalo Status assigned => confirmed
2021-03-11 13:06 Zeljan Rikalo Note Added: 0129569
2021-03-12 14:53 Zeljan Rikalo Note Added: 0129604
2021-03-12 14:53 Zeljan Rikalo File Added: qt5_issue37576_2.diff
2021-03-12 14:54 Zeljan Rikalo Status confirmed => feedback
2021-03-12 14:54 Zeljan Rikalo Note Added: 0129605
2021-03-15 09:24 Juha Manninen Note Added: 0129678
2021-03-15 09:24 Juha Manninen Status feedback => assigned
2021-03-15 11:34 Zeljan Rikalo Note Added: 0129683
2021-03-22 14:13 Zeljan Rikalo Status assigned => resolved
2021-03-22 14:13 Zeljan Rikalo Resolution open => fixed
2021-03-22 14:13 Zeljan Rikalo Fixed in Revision => 64857
2021-03-22 14:13 Zeljan Rikalo Widgetset QT5 => QT5
2021-03-22 14:13 Zeljan Rikalo Note Added: 0129829
2021-03-27 22:41 Juha Manninen Status resolved => closed