案例说明
- QFontDialog 对话框用以选择字体;
- 在这个例子中,我们创建了一个按钮和一个标签,通过QFontDialog来改变标签的字体。
demo.go
package main
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
"os"
)
func InitUi() *widgets.QMainWindow {
app := widgets.NewQMainWindow(nil, 0)
app.SetWindowTitle("Qt 教程")
app.SetGeometry2(300, 300, 300, 220)
app.SetWindowIcon(gui.NewQIcon5("images/app.ico"))
widget := widgets.NewQWidget(app, core.Qt__Widget)
widget.SetGeometry2(0, 0, 300, 220)
app.SetCentralWidget(widget)
vbox := widgets.NewQVBoxLayout2(widget)
lbl := widgets.NewQLabel2("Knowledge only matters", widget, 0)
lbl.Move2(130, 20)
vbox.AddWidget(lbl, 0, 0)
btn := widgets.NewQPushButton2("Dialog", widget)
btn.Move2(20, 20)
vbox.AddWidget(btn, 0, 0)
btn.ConnectClicked(func(checked bool) {
flag := false
font := widgets.NewQFontDialog(widget).GetFont2(&flag, widget)
if flag {
lbl.SetFont(font)
}
})
return app
}
func main() {
widgets.NewQApplication(len(os.Args), os.Args)
app := InitUi()
app.Show()
widgets.QApplication_Exec()
}