Gtk Grid with transparent cells

Hi, I need to create a transparent window (full screen) with a few widgets.
The widgets’ position and dimensions are given in pixels.
I found a way to achieve that, but Idon’t like it, and would like to get some advice:

I’m using the GtkGrid, attaching 2 transparent labels: (from 0 to screen width, and from 0 to screen height)
grid.attach(lbl1, 0, 0, 1920, 1);
grid.attach(lbl2, 0, 0, 1, 1080);

then I can attach the widgets like this:
grid.attach(view1, 100, 100, 800, 600);
grid.attach(view2, 0, 100, 320, 1080);

The grid is initialized with row\col homogenous=false, spacing=1

1 Like

Hello there.

If you need a window with transparent background, you should use CSS. The same goes for anything when you need a transparent background.

Next, if you need to position your widgets on absolute positions in screen, then a GtkFixed is appropriate.

But the general advice, because of a near infinite choice of available devices, you should try to avoid absolute positioning and reconsider the solution. We can also help if you could say what exactly is the requirement :slight_smile:

1 Like

First thx for your reply!
The requirement is to display some widgets over a transparent window.
The widget’s positions will be given to me in pixels, and the designer may ask for adjustments frequently.
For this reason I want to chose a container that excepts positions and and dimensions in pixels.

Transparency : CSS + Theming
Positioning : Gtk.Fixed
Pixel sizing : Gtk.Widget.set_width/height ?

This is a terrible idea. I know some designers think everything must be pixel perfect, but that’s mostly the result of working on static images instead of working on a GUI. User interfaces, by their nature, cannot really work on pixel perfect sizing and position. Accessibility, font sizes, localisation, screen constraints: all of these break any pixel perfect layout.

At most, you can guarantee pixel perfect alignment between UI elements, and possibly margin/border/padding; you should not, though, position widgets manually to given pixel positions, or give pixel-perfect sizing.


Hi, I appreciate your input very much, thx for your elaborate response!
What container would you suggest? A Grid? A Table?

Table is discontinued. GtkGrid is the preferred choice.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.