How do you replace HBox/VBox with Box/Grid

这一生的挚爱 提交于 2019-12-10 11:49:19

问题


The documentation for HBox and VBox includes the statement:

Deprecated: Use Box instead, which is a very quick and easy change. But we recommend switching to Grid, since Box will go away eventually.

However, it isn't obvious what the "quick and easy change" should be.

How do you use Box and/or Grid to achieve the functionality of VBox or HBox?


回答1:


One of the big changes in gtkmm3:

Gtk::Box, Gtk::ButtonBox, Gtk::IconView, Gtk::Paned, Gtk::ProgressBar, Gtk::ScaleButton, Gtk::ScrollBar and Gtk::Separator now derive from Gtk::Orientable, allowing their orientation (vertical or horizontal) to be specified without requiring the use of a derived class such as Gtk::HBox.

Although Grid isn't mentioned above, both containers now have a method set_orientation; Box can also take it in the constructor. So for Box, set the orientation and use your usual pack_start, pack_end.

With Grid, if you scrutinize the documentation, you'll see this line:

Grid can be used like a Box by just using Gtk::Container::add(), which will place children next to each other in the direction determined by the orientation property.

So, it should be as simple as setting the orientation and then add your child widgets.



来源:https://stackoverflow.com/questions/19532619/how-do-you-replace-hbox-vbox-with-box-grid

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