Need help writing a "no background" widget for wxWidgets (wxGTK) using GTK2

My question is about GTK2 and wxWidgets (actually wxGTK).

In wxGTK, all controls have a gray background by default and cannot be removed. I have a textured panel with custom child controls, and each of my controls has an ugly gray border that I cannot remove. I can only set the background color and make the panel color the same. Therefore, I need a type of white control in wxGTK.

I have many years of experience working with MS Windows before Linux. As far as I remember, in MS Windows every window control (that is, a widget) receives a WM_ERASEBKGND <event>) message and then a WM_PAINT message . The background is drawn in the WM_ERASEBKGND event handler , so you can easily leave the background of the parent element intact and draw all widget elements on top of it, simply by rewriting this handler.

This is not the case with wxGTK (and GTK2)!

In fact, all widgets in wxGTK are based on the custom "wxPizza" GTK widgets, which is derived from the GtkFixed widget. Any type of wxPizza widget has its own gdk window, so it is impossible to implement custom windowless widgets using standard wxGTK controls based on the wxPizza widget.

So, I decided to implement another GTK2 widget to make white controls available for wxWidgets. I implemented a windowless GTK2 widget derived from GtkFixed. To do this without windows, I used the gtk_widget_set_has_window function (another way is to set the GTK_NO_WINDOW flag).

Everything works, except for the drawing coordinates, which are in the coordinate space of the parent window. Thus, widget elements are drawn in the upper left position of the parent window. This is a problem that I cannot solve. Maybe I need to add a GtkEventBox to my custom widget?

Maybe there is another way to implement such functionality (foundationless widgets) in GTK2? What do you think about it?

Thanks in advance, Ilya

+4
source share
1 answer

Your question is quite old, but since there is now a trivial solution, it is better to write about it here, use the following code before calling Create() :

 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); 

We got it in wxWidgets 2.9.4 I believe.

+4
source

All Articles