View Issue Details

IDProjectCategoryView StatusLast Update
0037151LazarusLCLpublic2021-04-21 00:01
Reporterbald zhang Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformWindows, Linux 
Product Version2.0.8 
Summary0037151: label is shown even under a panel or groupbox
Descriptionrecently upgrade my development environment to 2.0.x, when design some testing app, found this issue.

a label on form, under a panel or a groupbox, it SHOULD hidden but it shown, both design time and run time.
if put a memo, the label was covered.

1.8.4 win32: good
2.0.8 win32: has issue
2.0.8 gtk2-linux: good.
trunk qt5-linux: has issue

haven't check every components.
Steps To Reproduceput a label on form
put a panel(or a groupbox), move the panel over the label, the label is still shown.
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetWin32/Win64, QT5
Attached Files

Relationships

related to 0035229 resolvedMichl Frame.Color not change the color of frame. 
related to 0038777 resolvedMichl ParentBackground of GroupBoxes cannot be set to true 

Activities

bald zhang

2020-05-29 00:02

reporter  

2.0.8-win32-design.png (12,805 bytes)   
2.0.8-win32-design.png (12,805 bytes)   
2.0.8-win32-running.png (12,991 bytes)   
2.0.8-win32-running.png (12,991 bytes)   

Zeljan Rikalo

2020-05-29 10:11

developer   ~0123122

That's because TPanel is transparent by default under qt,qt5 and win32

wp

2020-05-29 10:48

developer   ~0123125

Last edited: 2020-05-29 10:50

View 2 revisions

These are my observations for Win, did not check Linux:

TPanel:
  Turn off ParentBackground of the panel. This is the same behavior as in Delphi.

TGroupBox:
  By default, The Groupbox is transparent in Delphi like in Lazarus. But in Delphi there is a ParentBackground property again which can be used to make the GroupBox opaque - this is missing in Lazarus. In Lazarus you can achieve opaquness by setting the Groupbox's Color to a value different from clDefault.

bald zhang

2020-05-30 00:08

reporter   ~0123134

Last edited: 2020-05-30 00:11

View 2 revisions

I just looking for something like "Transparent" but didn't notice the ParentBackground property,
and there is nothing about this in wiki..

Make a more detail sample and found Panel.ParentBackground is not working on qt5.
and there is different between design and run time.

on gtk2: label was covered in anyway.
win32-design.png (18,375 bytes)   
win32-design.png (18,375 bytes)   
win32-running.png (16,519 bytes)   
win32-running.png (16,519 bytes)   
qt5-design.png (14,440 bytes)   
qt5-design.png (14,440 bytes)   
qt5-running.png (12,091 bytes)   
qt5-running.png (12,091 bytes)   

Ondrej Pokorny

2021-03-24 16:20

developer   ~0129856

@ wp: > In Lazarus you can achieve opaquness by setting the Groupbox's Color to a value different from clDefault.

That doesn't truly work on win32. See the attached project. If the group box is on a tabsheet (or any other control placed on a tabsheet), it stays transparent. If it is on a coloured panel, the caption takes the color of that panel.
GroupBoxColor.7z (1,089 bytes)
screenshot.png (6,342 bytes)   
screenshot.png (6,342 bytes)   

Zeljan Rikalo

2021-03-24 19:14

developer   ~0129861

Why not using csOpaque for TGroupBox.ControlStyle ? AFAIR it should work.

Ondrej Pokorny

2021-03-26 09:55

developer   ~0129907

@Zeljan > Why not using csOpaque for TGroupBox.ControlStyle ? AFAIR it should work.

That is actually a good idea - thanks for it. Just tested it and it works half the way - the group box is opaque without the caption. See the screenshot. But it is definitely a direction in the right way. Btw. I just tested Delphi and they handle colored group boxes fine, so it should be possible.
screenshot2.png (6,200 bytes)   
screenshot2.png (6,200 bytes)   

Ondrej Pokorny

2021-03-26 10:18

developer   ~0129908

Applied the csOpaque style in r64871. I still have to find out why the label is transparent and doesn't apply the groupbox style.

Michl

2021-04-01 21:08

developer   ~0130028

> I still have to find out why the label is transparent and doesn't apply the groupbox style.

Normally answer in https://stackoverflow.com/questions/61532510/find-text-height-and-set-caption-background-color-of-bs-groupbox-control should work.

But we erase the background by LCL and there the modified brush is gone. There always Brush.Reference.Handle of TWinControl is used.

I get it to work, but it is a very very ugly workaround. Now I don't know how this can be done in a nice way. Maybe you have a idea?!

Ugly patch added.
GroupBox.patch (2,482 bytes)   
Index: lcl/graphics.pp
===================================================================
--- lcl/graphics.pp	(revision 64890)
+++ lcl/graphics.pp	(working copy)
@@ -2009,6 +2009,8 @@
     (Value: EASTEUROPE_CHARSET;  Name: 'EASTEUROPE_CHARSET'),
     (Value: OEM_CHARSET;         Name: 'OEM_CHARSET'));
 
+var
+  EraseBackgroundBrush: HBRUSH = 0;
 
 (***************************************************************************
  ***************************************************************************)
Index: lcl/include/wincontrol.inc
===================================================================
--- lcl/include/wincontrol.inc	(revision 64890)
+++ lcl/include/wincontrol.inc	(working copy)
@@ -5046,7 +5046,12 @@
 begin
   if DC = 0 then Exit;
   ARect := Rect(0, 0, Width, Height);
-  FillRect(DC, ARect, HBRUSH(Brush.Reference.Handle));
+  if EraseBackgroundBrush <> 0 then
+  begin
+    FillRect(DC, ARect, EraseBackgroundBrush);
+    EraseBackgroundBrush := 0;
+  end else
+    FillRect(DC, ARect, HBRUSH(Brush.Reference.Handle));
 end;
 
 {------------------------------------------------------------------------------
Index: lcl/interfaces/win32/win32wsstdctrls.pp
===================================================================
--- lcl/interfaces/win32/win32wsstdctrls.pp	(revision 64890)
+++ lcl/interfaces/win32/win32wsstdctrls.pp	(working copy)
@@ -621,19 +621,28 @@
       var MsgResult: Windows.LResult; var WinProcess: Boolean): Boolean;
 var
   Info: PWin32WindowInfo;
+  AGroupBox: TGroupBox;
 begin
   Result := False;
   case Msg of
     WM_CTLCOLORSTATIC:
     begin
+      if not ThemeServices.ThemesEnabled then Exit;
       Info := GetWin32WindowInfo(HWND(LParam));
-      Result := Assigned(Info) and ThemeServices.ThemesEnabled and (Info^.WinControl.Color = AWinControl.Color);
-      if Result then
+      if not Assigned(Info) or not (Info^.WinControl is TGroupBox) then
+        Exit;
+      Result := True;
+      AGroupBox := TGroupBox(Info^.WinControl);
+      if AGroupBox.ParentBackground or AGroupBox.ParentColor then
       begin
         ThemeServices.DrawParentBackground(HWND(LParam), HDC(WParam), nil, False);
         MsgResult := GetStockObject(HOLLOW_BRUSH);
         WinProcess := False;
         SetBkMode(HDC(WParam), TRANSPARENT);
+      end else begin
+        EraseBackgroundBrush := AGroupBox.Brush.Reference.Handle;
+        MsgResult := 1;
+        WinProcess := False;
       end;
     end;
   end;
GroupBox.patch (2,482 bytes)   

Issue History

Date Modified Username Field Change
2020-05-29 00:02 bald zhang New Issue
2020-05-29 00:02 bald zhang File Added: 2.0.8-win32-design.png
2020-05-29 00:02 bald zhang File Added: 2.0.8-win32-running.png
2020-05-29 10:11 Zeljan Rikalo Note Added: 0123122
2020-05-29 10:48 wp Note Added: 0123125
2020-05-29 10:50 wp Note Edited: 0123125 View Revisions
2020-05-30 00:08 bald zhang Note Added: 0123134
2020-05-30 00:08 bald zhang File Added: win32-design.png
2020-05-30 00:08 bald zhang File Added: win32-running.png
2020-05-30 00:08 bald zhang File Added: qt5-design.png
2020-05-30 00:08 bald zhang File Added: qt5-running.png
2020-05-30 00:11 bald zhang Note Edited: 0123134 View Revisions
2021-03-24 16:20 Ondrej Pokorny Note Added: 0129856
2021-03-24 16:20 Ondrej Pokorny File Added: GroupBoxColor.7z
2021-03-24 16:20 Ondrej Pokorny File Added: screenshot.png
2021-03-24 19:14 Zeljan Rikalo Note Added: 0129861
2021-03-26 09:55 Ondrej Pokorny Note Added: 0129907
2021-03-26 09:55 Ondrej Pokorny File Added: screenshot2.png
2021-03-26 10:18 Ondrej Pokorny Note Added: 0129908
2021-03-27 13:28 Michl Relationship added related to 0035229
2021-04-01 21:08 Michl Note Added: 0130028
2021-04-01 21:08 Michl File Added: GroupBox.patch
2021-04-21 00:01 Michl Relationship added related to 0038777