d - 为什么按钮没有展开以填满所有空间?
问题描述
我制作了一个小型测试 GtkD DUB 项目(以 GtkD 3.9.0 作为依赖项)来制作一个最小的可重现示例,说明我在一个更大的项目中遇到的问题。显然 Box 没有扩展中间的 Widget(在本例中为 Button)以占用所有可用空间。难道我做错了什么?
import gtk.MainWindow;
import gtk.Label;
import gtk.Button;
import gtk.Main;
import gtk.Box;
void main(string[] args) {
Main.init(args);
MainWindow window = new MainWindow("Pack test");
Box box = new Box(Orientation.VERTICAL, 0);
Label topLabel = new Label("Top");
box.add(topLabel);
box.packStart(topLabel, false, false, 0);
Button bigButton = new Button("Big button");
box.add(bigButton);
box.packStart(bigButton, true, true, 0);
Label bottomLabel = new Label("Bottom");
box.add(bottomLabel);
box.packStart(bottomLabel, false, false, 0);
window.add(box);
window.setDefaultSize(800, 600);
window.showAll();
Main.run();
}
当我在 Glade 中制作相同的结构并进行预览时,它显示按钮已展开以填充所有可用空间,所以要么我做错了,要么 GtkD 中存在错误......
解决方案
Mike Wey(GtkD 作者)解决了这个线程中的谜团 - https://forum.gtkd.org/groups/GtkD/thread/2069/ ...显然我同时调用了 add() 和 packStart() 却不知道packStart() 实际上添加了小部件,所以看起来像添加小部件两次(一次使用 add(),然后使用 packStart())会使事情变得混乱。
因此删除了 add() 调用的代码按预期工作:
import gtk.MainWindow;
import gtk.Label;
import gtk.Button;
import gtk.Main;
import gtk.Box;
void main(string[] args) {
Main.init(args);
MainWindow window = new MainWindow("Pack test");
Box box = new Box(Orientation.VERTICAL, 0);
Label topLabel = new Label("Top");
//box.add(topLabel);
box.packStart(topLabel, false, false, 0);
Button bigButton = new Button("Big button");
//box.add(bigButton);
box.packStart(bigButton, true, true, 0);
Label bottomLabel = new Label("Bottom");
//box.add(bottomLabel);
box.packStart(bottomLabel, false, false, 0);
window.add(box);
window.setDefaultSize(800, 600);
window.showAll();
Main.run();
}
推荐阅读
- python - RuntimeError: Unsupported image type, must be 8bit gray or RGB image
- powershell - 替换文件名powershell中文本前的一个字符
- reactjs - Firebase 数据库不是 ReactJS 应用程序中的函数错误
- visual-studio-code - VSCodium 在 Mac OS Mojave 中的“escape”键上随机崩溃。我怎样才能找到问题?
- c# - 查找 tfs 变更集中更改的功能
- python-3.x - python中fun1和fun1()的区别
- c# - C# BHO:单击扩展按钮时打开新的 Internet Explorer 选项卡
- vb.net - 自定义字典类未使用正确的文件名进行序列化
- javascript - 防止在 Materialize CSS 菜单中按 Tab 时关闭下拉菜单
- android - 从 Firebase 存储下载的文件不可读