如何使用Gtk::Grid放置小部件,类似于Gtkmm-3中的Gtk::Table
How to place widgets with Gtk::Grid similarly to Gtk::Table in Gtkmm-3
最初我学的是pyGtk。几个月后,我决定改用Gtkmm。阅读官方文档,它告诉我Gtk::Table已弃用,我应该使用Gtk::Grid。
如果我想把小部件放在第2行和第3行之间,第4列和第5列之间,我可以在Gtk::Table中使用下面的代码。
// Create variable.
Gtk::Table table;
//Initiate table.
table(10,10,true);
//Place the widget in the proper position.
// table.attach(widget, left_attach, right_attach, top_attach, bottom_attach);
table.attach(widget,4,5,2,3);
在阅读了Gtk::Grid之后,我尝试了同样的事情,但这次使用了Gtk::Grid。
// Create variable.
Gtk::Grid grid;
//Place the widget in the proper position.
//grid.attach(widget, left, top, higth, width);
grid.attach(widget,4,2,1,1);
但是当我尝试最后一个代码的小部件(一个按钮),仍然放在左上角。有人知道我哪里做错了吗?Gtk::Grid有能力做我想做的事情吗?
按钮保持在左上角,因为在第一行或前三列中没有其他小部件占用任何空间,所以它们折叠为零。
可能你想要的是
grid.set_row_homogeneous(true);
grid.set_column_homogeneous(true);
然后在位置0,0和位置9,9附加空白小部件,以确保网格有10行和10列。
相关文章:
- 类似于strcat()的函数出现问题
- 如何将C++闭包与变量参数同时重用——类似于JavaScript
- 算术运算的结果类似于:C浮点变量中的1/3
- 在数组中输入 n 个整数的列表,并以类似于钟摆来回移动的方式排列它们. 输入-1 3 2 5 4,输出5 3 1 2 4
- 创建类似于布尔值的变量类型
- 如何在 Arduino 字符串的开头添加元素.类似于 JS unshift();
- Java 中是否有类似于 C++ 中引用类型"&"的内容?
- C++未知长度字符串的数组,其行为类似于 Python 字符串列表
- 如何创建类似于 QVariant 的变体类
- 对于多个字符(如 ETX/STX 对),是否有类似于 std::quote 的东西
- 初始化命名空间中的变量是否类似于将它们初始化为类成员?
- C++中用于结构的纯数组的类似于TableView/DataFrame的通用功能
- 有没有类似于stoi的函数可以用于模板类
- 如何编写一个类似于kernellist_head的c++风格的双链表实现
- 序列化模式类似于boost::序列化
- 构造一个类似于JSON文件c++的字符串
- 多重继承中的派生类的行为类似于聚合
- 如何使更安全的C++变体访问者,类似于切换语句?
- C++ Python 中是否有类似于 help() 的函数
- 如何使用Gtk::Grid放置小部件,类似于Gtkmm-3中的Gtk::Table