开发者

Need help writing "backgroundless" widget for wxWidgets (wxGTK) using GTK2

My question is concerned with GTK2 and wxWidgets (actually wxGTK).

In wxGTK all controls have grey background by default and it is impossible to remove it. I have a textured panel with custom child controls and each of my controls has an ugly grey border which I can't remove. I can only set some background color and make the panel's color the same. So I need a kind of "backgroundless" control in wxGTK.

I have many years of MS Windows experience before Linux. As far as I remember, in MS Windows each windowed control (i.e. widget) receives a WM_ERASEBKGND message (event) and then WM_PAINT message. The background is drawn in WM_ERASEBKGND event handler, so you can easily leave the parent control's background untouched and paint all of widget's elements on top of it by simply rewriting this handler.

That's not the case with wxGTK (and GTK2)!

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

So I decided to implement another one GTK2 widget to make "backgroundless" controls available to wxWidgets. I implemented a windowless GTK2 widget, derived from GtkFixed. To make it windowless I used gtk_widget_set_has_window function (another way is to set a GTK_NO_WINDOW flag).

Everything works, except for draw coordinates, which are in parent window coordinate space. So the widget's elements are drawn at the parent window's top left position. That's the problem that I can't resolve. Maybe I need to add a GtkEventBox to my custom widget?

Maybe there are ano开发者_StackOverflowther ways to implement such functionality (backgroundless widgets) in GTK2? What do you think about that?

Thanks in advance, Ilya


Your question is pretty old, but as there is now a trivial solution, it is better to write about it here, use the following code before your Create() call:

SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);

We got this into wxWidgets 2.9.4 I believe.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜