From 4a33371558ec8666b18ad61ede44f71a99754f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Sun, 21 Sep 2025 17:15:22 +0200 Subject: [PATCH] Added transparency test code to SimpleOSRBrowser in QT --- .../SimpleOSRBrowser/umainform.pas | 27 +++++++++++++++---- .../SimpleOSRBrowser/umainform.pas | 27 +++++++++++++++---- update_CEF4Delphi.json | 2 +- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/demos/Lazarus_Linux_QT5/SimpleOSRBrowser/umainform.pas b/demos/Lazarus_Linux_QT5/SimpleOSRBrowser/umainform.pas index d9bfbc52..20cf2fb2 100644 --- a/demos/Lazarus_Linux_QT5/SimpleOSRBrowser/umainform.pas +++ b/demos/Lazarus_Linux_QT5/SimpleOSRBrowser/umainform.pas @@ -10,7 +10,12 @@ uses {$IFDEF LCLQT}qt4,{$ENDIF} {$IFDEF LCLQT5}qt5,{$ENDIF} {$IFDEF LCLQT6}qt6,{$ENDIF} - uCEFBufferPanel, uCEFChromium, uCEFInterfaces, uCEFTypes; + uCEFBufferPanel, uCEFChromium, uCEFInterfaces, uCEFTypes; + +const + // Set this constant to True and load "file:////bin/transparency.html" to test a + // transparent browser. + TRANSPARENT_BROWSER = True; type @@ -219,6 +224,13 @@ begin GlobalCEFApp.DisableZygote := True; GlobalCEFApp.WindowlessRenderingEnabled := True; GlobalCEFApp.OnContextInitialized := @GlobalCEFApp_OnContextInitialized; + + // If you need transparency leave the GlobalCEFApp.BackgroundColor property + // with the default value or set the alpha channel to 0 + if TRANSPARENT_BROWSER then + GlobalCEFApp.BackgroundColor := CefColorSetARGB($00, $00, $00, $00) + else + GlobalCEFApp.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF); end; function StartMainProcess: boolean; @@ -612,11 +624,16 @@ begin // monitor where the main application form is located. GlobalCEFApp.UpdateDeviceScaleFactor; - UpdatePanelOffset; + UpdatePanelOffset; - // opaque white background color - Chromium1.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF); - Chromium1.DefaultURL := UTF8Decode(AddressCb.Text); + // If you need transparency leave the Chromium1.Options.BackgroundColor property + // with the default value or set the alpha channel to 0 + if TRANSPARENT_BROWSER then + Chromium1.Options.BackgroundColor := CefColorSetARGB($00, $00, $00, $00) + else + Chromium1.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF); + + Chromium1.DefaultURL := UTF8Decode(AddressCb.Text); Chromium1.CreateBrowser; end; diff --git a/demos/Lazarus_Linux_QT6/SimpleOSRBrowser/umainform.pas b/demos/Lazarus_Linux_QT6/SimpleOSRBrowser/umainform.pas index 71bbe732..6a0b34c0 100644 --- a/demos/Lazarus_Linux_QT6/SimpleOSRBrowser/umainform.pas +++ b/demos/Lazarus_Linux_QT6/SimpleOSRBrowser/umainform.pas @@ -11,6 +11,11 @@ uses {$IFDEF LCLQT5}qt5,{$ENDIF} {$IFDEF LCLQT6}qt6,{$ENDIF} uCEFBufferPanel, uCEFChromium, uCEFInterfaces, uCEFTypes; + +const + // Set this constant to True and load "file:////bin/transparency.html" to test a + // transparent browser. + TRANSPARENT_BROWSER = True; type @@ -218,7 +223,14 @@ begin GlobalCEFApp.RootCache := 'RootCache'; GlobalCEFApp.SetCurrentDir := True; GlobalCEFApp.DisableZygote := True; - GlobalCEFApp.OnContextInitialized := @GlobalCEFApp_OnContextInitialized; + GlobalCEFApp.OnContextInitialized := @GlobalCEFApp_OnContextInitialized; + + // If you need transparency leave the GlobalCEFApp.BackgroundColor property + // with the default value or set the alpha channel to 0 + if TRANSPARENT_BROWSER then + GlobalCEFApp.BackgroundColor := CefColorSetARGB($00, $00, $00, $00) + else + GlobalCEFApp.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF); end; function StartMainProcess: boolean; @@ -612,11 +624,16 @@ begin // monitor where the main application form is located. GlobalCEFApp.UpdateDeviceScaleFactor; - UpdatePanelOffset; + UpdatePanelOffset; - // opaque white background color - Chromium1.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF); - Chromium1.DefaultURL := UTF8Decode(AddressCb.Text); + // If you need transparency leave the Chromium1.Options.BackgroundColor property + // with the default value or set the alpha channel to 0 + if TRANSPARENT_BROWSER then + Chromium1.Options.BackgroundColor := CefColorSetARGB($00, $00, $00, $00) + else + Chromium1.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF); + + Chromium1.DefaultURL := UTF8Decode(AddressCb.Text); Chromium1.CreateBrowser; end; diff --git a/update_CEF4Delphi.json b/update_CEF4Delphi.json index d34dfc36..4f415819 100644 --- a/update_CEF4Delphi.json +++ b/update_CEF4Delphi.json @@ -2,7 +2,7 @@ "UpdateLazPackages" : [ { "ForceNotify" : true, - "InternalVersion" : 791, + "InternalVersion" : 792, "Name" : "cef4delphi_lazarus.lpk", "Version" : "140.1.14" }