Zealseeker
Zealseeker

Reputation: 823

How to make a widget in the front of ohter widgets in gtk

I wanted to make a widget (custom widget) at the front of a container (fixed) like setting "z-index" in web design. But I didn't find any method that can do it.

For example.

Button bt1 = new Button();
Button bt2 = new Button();
bt1.WidthRequest = 100;
bt2.WidthRequest = 100;
Fixed fx1 = new Fixed();
fx1.put(bt1,0,0);
fx1.put(bt2,50,0);

Then bt2 will cover the bt1 because bt2 is the last-added widget. Now I want bt1 to cover bt2, i.e. bt1 is at the front of fx1. How to do so?

There's a similar question whose whose answer can't solve it. GTK# Widget in front of another widget

Upvotes: 1

Views: 997

Answers (1)

Zealseeker
Zealseeker

Reputation: 823

I solved it myself!

Using GdkWindow.Raise() as pointed out here: Stacking widgets in Gtk+

In my example, using bt1.GdkWindow.Raise() will have the effect of a bring-to-front operation of bt1 in the container.

Note that if a widget isn't a "window" (I don't precisely know the definition of what a window is in detail with my limited knowledge about Gtk#) this won't work.

In that case the widget can be encapsulated in an 'EventBox' and Raise() should be called on its GdkWindow instead (similarly to how "ModifyBg(...)" doesn't work on some widgets but it does for event-boxes).

Upvotes: 1

Related Questions