go - 控制 GTK 小部件大小
问题描述
我想要一个 GTK 应用程序,它作为第一次迭代应该有一个长列表、一个隐藏的小部件和一个底线。所有这些都应该垂直布局。
到目前为止,我尝试使用 expand 方法执行此操作,但似乎没有任何效果:
package main
import (
"log"
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
)
func main() {
// Initialize GTK without parsing any command line arguments.
gtk.Init(nil)
// Create a new toplevel window, set its title, and connect it to the
// "destroy" signal to exit the GTK main loop when it is destroyed.
win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
if err != nil {
log.Fatal("Unable to create window:", err)
}
win.SetDecorated(false)
win.SetTitle("Simple Example")
win.Connect("destroy", func() {
gtk.MainQuit()
})
// Create a new label widget to show in the window.
l, err := gtk.LabelNew("Hello, gotk3!")
if err != nil {
log.Fatal("Unable to create label:", err)
}
ls, err := gtk.ListStoreNew(glib.TYPE_STRING, glib.TYPE_STRING)
if err != nil {
log.Fatal("Unable to create list:", err)
}
tv, err := gtk.TreeViewNewWithModel(ls)
if err != nil {
panic(err)
}
lb, err := gtk.ListBoxNew()
if err != nil {
panic(err)
}
fr, err := gtk.ListBoxRowNew()
if err != nil {
panic(err)
}
sr, err := gtk.ListBoxRowNew()
if err != nil {
panic(err)
}
tr, err := gtk.ListBoxRowNew()
if err != nil {
panic(err)
}
fr.Add(tv)
tr.Add(l)
fr.SetVExpand(true)
tr.SetVExpand(false)
lb.Add(fr)
lb.Add(sr)
lb.Add(tr)
lb.SetVExpand(true)
// Add the label to the window.
win.Add(lb)
// Set the default window size.
win.SetDefaultSize(800, 600)
// Recursively show all widgets contained in this window.
win.ShowAll()
// Begin executing the GTK main loop. This blocks until
// gtk.MainQuit() is run.
gtk.Main()
}
所以我的问题是,是否有任何关于 GTK 如何进行布局以及如何让我想要的布局工作的综合文章。
解决方案
似乎这是不可能的ListBox
。切换到Box
并按预期工作。
推荐阅读
- reactjs - redux props 两次接收数据
- c++ - 使用 C++ 的日期库读取时间
- powerbi - 根据类别的最小值查找
- typeorm - Typeorm - 左连接并仅选择关系实体
- python - Discord.py 静音命令
- html - Accordion 内的工具提示
- spring-boot - Spring Boot Mapping 不起作用:MappedBy 引用了一个未知的目标实体属性
- swiftui - SwiftUI - 将数据从数组传递到结构
- reactjs - 使用 react-select 和 react-hook-form 返回正确的值
- c# - 插入垂直滚动条以查看选项卡项的内容