func (p *MainWindow) createStdTab() *qt5.Widget { w := qt5.NewWidget() vbox := qt5.NewVBoxLayout() w.SetLayout(vbox) ed := qt5.NewLineEdit() ed.SetInputMask("0000-00-00") ed.SetText("2012-01-12") lbl := qt5.NewLabel() lbl.SetText("Label") btn := qt5.NewButton() btn.SetText("Button") chk := qt5.NewCheckBox() chk.SetText("CheckBox") radio := qt5.NewRadio() radio.SetText("Radio") cmb := qt5.NewComboBox() cmb.AddItem("001") cmb.AddItem("002") cmb.AddItem("003") cmb.SetCurrentIndex(2) fmt.Println(cmb.CurrentIndex()) cmb.OnCurrentIndexChanged(func(v int) { fmt.Println(cmb.ItemText(v)) }) slider := qt5.NewSlider() slider.SetTickInterval(50) slider.SetTickPosition(qt5.TicksBothSides) slider.SetSingleStep(1) scl := qt5.NewScrollBar() fmt.Println(slider.Range()) dial := qt5.NewDial() dial.SetNotchesVisible(true) dial.SetNotchTarget(10) fmt.Println(dial.NotchSize()) vbox.AddWidget(ed) vbox.AddWidget(lbl) vbox.AddWidget(btn) vbox.AddWidget(chk) vbox.AddWidget(radio) vbox.AddWidget(cmb) vbox.AddWidget(slider) vbox.AddWidget(scl) vbox.AddWidget(dial) vbox.AddStretch(0) return w }
func (p *MainWindow) createMyTab() *qt5.Widget { w := qt5.NewWidget() vbox := qt5.NewVBoxLayout() hbox := qt5.NewHBoxLayout() my := new(MyWidget).Init() lbl := qt5.NewLabel() lbl.SetText("this is custome widget - draw lines") btn := qt5.NewButton() btn.SetText("Clear") btn.OnClicked(func() { my.Clear() }) hbox.AddWidget(lbl) hbox.AddWidgetWith(btn, 0, qt5.AlignRight) vbox.AddLayout(hbox) vbox.AddWidgetWith(my, 1, 0) w.SetLayout(vbox) return w }
func main_ui() { qt5.OnInsertObject(func(item interface{}) { fmt.Println("add item", item) }) qt5.OnRemoveObject(func(item interface{}) { fmt.Println("remove item", item) }) w := qt5.NewWidget() defer w.Close() w.SetWindowTitle("This is a test") fmt.Println(w.WindowTitle()) vbox := qt5.NewVBoxLayout() fmt.Println(vbox) w.SetLayout(vbox) lbl := qt5.NewLabel() lbl.SetText("<h2><i>Hello</i> <font color=blue><a href=\"ui\">UI</a></font></h2>") lbl.OnLinkActivated(fnTEST) vbox.AddWidget(lbl) vbox.AddStretch(0) //runtime.GC() btn := qt5.NewButton() btn.SetText("WbcdefgwqABCDEFQW") font := btn.Font() defer font.Close() font.SetPointSize(16) btn.SetFont(font) fmt.Println("f3->", btn.Font()) btn2 := qt5.NewButton() font.SetPointSize(18) btn2.SetAttr("text", "WbcdefgwqABCDEFQW") btn2.SetAttr("font", font) btn.OnClicked(func() { fmt.Println(btn) btn.Close() }) btn.OnCloseEvent(func(e *qt5.CloseEvent) { fmt.Println("Close", e) }) btn3 := qt5.NewButton() btn3.SetText("Exit") btn3.OnClicked(func() { qt5.Exit(0) }) l := w.Layout() fmt.Println("ll", l) l.AddWidget(btn) l.AddWidget(btn2) l.AddWidget(btn3) //vbox.AddWidget(btn) f := btn2.Attr("parent") fmt.Println("parent->", f, f == nil) fmt.Println(btn.Font()) w.OnResizeEvent(func(e *qt5.ResizeEvent) { fmt.Println(e) }) w.OnPaintEvent(func(ev *qt5.PaintEvent) { fnPaint(ev, w) }) //w.Show() w.SetVisible(true) <-exit }
func ui_main() { w := qt5.NewWidget() lbox := qt5.NewVBoxLayout() lbl1 := qt5.NewLabel() lbl1.SetText("This is a info1") lbl2 := qt5.NewLabel() lbl2.SetText("This is a info2") ed1 := qt5.NewLineEdit() printInfo := func() { info := qt5.Value("info") ed1.SetText(fmt.Sprint(info)) } lbox.AddWidget(lbl1) lbox.AddWidget(lbl2) lbox.AddWidget(ed1) rbox := qt5.NewVBoxLayout() btn1 := qt5.NewButton() btn1.SetText("Change") btn2 := qt5.NewButton() btn2.SetText("Value") btn3 := qt5.NewButton() btn3.SetText("SetValue") rbox.AddWidget(btn1) rbox.AddWidget(btn2) rbox.AddWidget(btn3) b := true btn1.OnClicked(func() { var text string if b { qt5.SetKey(lbl1, "info", "text") text = "info1" } else { qt5.SetKey(lbl2, "info", "text") text = "info2" } b = !b btn1.SetText(text) }) btn2.OnClicked(printInfo) btn3.OnClicked(setInfo) hbox := qt5.NewHBoxLayout() hbox.AddLayout(lbox) hbox.AddLayout(rbox) w.SetLayout(hbox) w.Show() qt5.Run() }