Skip to content

GTK3 Can Be a Pain in the Themes

Starting with Xojo 2017r2, Linux apps use GTK3. Since Xojo uses native controls that means your app’s controls will use the theme of the Linux distribution the app runs on. This can sometimes mean that your app’s UI will not look exactly like what you designed in the Layout Editor because a theme may dramatically change control sizes and padding.┬áThis is a problem that can occur with any modern GTK3 app.

If this is a problem for your apps, there are a couple ways you can work around it.

Use Fixed/Locked Control Padding

For many apps, the primary concern is to not have controls change their size or position depending on the theme being used. You can ensure specific styling for controls in your apps by using a static amount of padding that won’t change regardless of the user’s theme selection. This has the benefit of letting your app use other aspects of the theme, such as colors, while maintaining control layout better.

Have Your App Load and Use a Specific Theme

If you would like your app to use a specific theme so that your layout works exactly as you want it, you can bundle a theme and load it when your app starts. Your app will use this loaded theme regardless of what the user has selected as a theme for the distribution.

Both of these solutions can be handled by Declares that you put in your App.Open event handler.

We’ve put together a couple sample projects to demonstrate these two solutions:

Download GTK3ThemeExamples

The examples should be sufficient for most apps. But if you require more control of themes and how they render widgets, you will have to dig deeper into Linux. The GTK+ Inspector can be a great tool for this as it lets you see property and widget information in real time.

For more information and details, refer to GTK3 Themes in the User Guide.