Stacking widgets in Gtk+

人盡茶涼 提交于 2019-12-04 17:53:12

I don't think there is a proper container in standard GTK. I would subclass Gtk::Fixed... it is still the closest one you can get, and if you use gtkmm then subclassing shouldn't be very difficult¹. Then you can control the dimensions of all widgets, stretching one selected child to fill space.

To control Z-axis you will probably need to manipulate widget's X windows--check GDK documentation on topic of GDK windows². I remember that in PyGTK each widget has gtk.Widget.window property, I guess that the same is for gtkmm. This assumes that all your child widgets have X windows, so f.e. you'll need to wrap Gtk::Label inside Gtk::EventBox.

¹ http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/chapter-customwidgets.html

² http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGdk_1_1Window.html#6eef65b862344ad01b01e527f2c39741

I had this exact issue using a Gtk::Fixed (actually gtk.Fixed -- pygtk -- but I think it's all the same underneath) and I was able to handle it quite easily by manipulating each widget's window.

In my case, the widgets already are EventBox instances, and I just needed to make sure that the one I was dragging around was on top, because otherwise it slid underneath others, which looked quite wrong. The solution was as simple as calling "widget.window.raise_()" to raise the widget's underlying window when the widget was clicked to begin the drag.

So I'm basically just reaffirming that the previous answer works, but I wanted to point out that it's actually pretty easy. It sounds like you may need to create some EventBoxes to hold your widgets, but after that it should just work.

You can see the code I was working on at http://github.com/divegeek/BlockHead

I was able to do exactly that -

display one widget filling the entire space, and then another on top at a fixed location, both visible at the same time

in gtk2 by using GtkFixed, working out a suitable insertion order (first inserted - bottom, last inserted - top), and - most importantly!! - forcing GtkFixed to have it's own window:

`f := gtk_fixed_new();
gtk_widget_set_has_window(f, 1);`

If you don't do set_has_window(f, 1), all children windows will be inserted into some parent widget/window (see gtk_fixed_realize() in gtkfixed.c), and that might create z-order mess.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!