Lazarus Dark Mode Tutorial (Windows Only)
Lazarus Dark Mode Tutorial (Windows Only)
In this article, I’m going to show you how to add dark mode to your Lazarus LCL application on Windows (and Lazarus IDE as well!)
PS: This method is Windows only. Other platforms do not need this method, as setting the system theme to dark is enough for LCL applications to switch to dark mode in those enviornments.
Adding dark mode to Lazarus IDE
Prerequisites
Make sure that:
- You’re on the latest version of Lazarus IDE
- You’re using the correct architecture for your device (i.e x86_64 version of the IDE and FPC if you’re on 64-bit, etc)
- You have a clean install of Lazarus (This is avoid any configuration issues which might prevent the package from applying the theme correctly. I figured this out the hard way :P)
- You have enabled dark mode in Windows settings
Installing dark mode
- Open Lazarus IDE
- Go to https://github.com/zamtmn/metadarkstyle/ and follow the instructions there on installing the
metadarkstyle
package - After you’ve installed it, rebuild the IDE
Final checks
- If
metadarkstyle
was installed correctly, in Tools > Options you will have an option called Dark Style under Environment - Next, set the
PreferredAppMode
option toAllow Dark
- Restart your IDE and it should have a dark theme
Using dark theme in your own application
- Open your project
- Make sure you have done steps 2 and 3 from the section Installing dark mode
- Go to Project > Project Inspector…
- Click Add > New Requirement
- In the Package Name field, search for
metadarkstyle
and add it to your project - Also add the
metadarkstyledsgn
package to your project - After you’ve added it, go to your application file (it should have a
.lpr
extension) - In the
uses
section, add:1 2 3 4 5
uses // ... uDarkStyleParams, uMetaDarkStyle, uDarkStyleSchemes,
- Under the
begin
section, add:1 2
PreferredAppMode := pamAllowDark; uMetaDarkStyle.ApplyMetaDarkStyle(DefaultDark);
- Now run your application and it should have dark mode!
This post is licensed under CC BY 4.0 by the author.