func NewCalclatorForm() (*CalclatorForm, error) { w := &CalclatorForm{} w.QWidget = ui.NewQWidget() file := ui.NewQFileWithName(":/forms/calculatorform.ui") if !file.Open(ui.QIODevice_ReadOnly) { return nil, errors.New("error load ui") } loader := ui.NewQUiLoader() formWidget := loader.Load(file) if formWidget == nil { return nil, errors.New("error load form widget") } w.spinBox1 = ui.NewQSpinBoxFromDriver(formWidget.FindChild("inputSpinBox1")) w.spinBox2 = ui.NewQSpinBoxFromDriver(formWidget.FindChild("inputSpinBox2")) w.outputLable = ui.NewQLabelFromDriver(formWidget.FindChild("outputWidget")) if ui.IsValidDriver(w.spinBox1) && ui.IsValidDriver(w.spinBox2) && ui.IsValidDriver(w.outputLable) { fnChanged := func() { w.outputLable.SetText(fmt.Sprintf("%d", w.spinBox1.Value()+w.spinBox2.Value())) } w.spinBox1.OnValueChanged(func(string) { fnChanged() }) w.spinBox2.OnValueChanged(func(string) { fnChanged() }) } layout := ui.NewQVBoxLayout() layout.AddWidget(formWidget) w.SetLayout(layout) w.SetWindowTitle("Calculator Builder") return w, nil }
func main_ui() { btn := ui.NewQPushButton() btn.SetText("Async") clear := ui.NewQPushButton() clear.SetText("Clear") edit := ui.NewQPlainTextEdit() edit.SetReadOnly(true) btn.OnClicked(func() { for i := 0; i < 10; i++ { go func(i int) { start := time.Now() <-time.After(1e7) offset := time.Now().Sub(start) ui.Async(func() { edit.AppendPlainText(fmt.Sprintf("Task %v %v", i, offset)) }) }(i) } }) clear.OnClicked(func() { edit.Clear() }) hbox := ui.NewQHBoxLayout() hbox.AddWidget(btn) hbox.AddWidget(clear) vbox := ui.NewQVBoxLayout() vbox.AddLayout(hbox) vbox.AddWidget(edit) widget := ui.NewQWidget() widget.SetLayout(vbox) widget.Show() }
func NewDialog() *Dialog { dlg := &Dialog{} dlg.QDialog = ui.NewQDialog() vbox := ui.NewQVBoxLayout() dlg.SetLayout(vbox) dlg.widdly = NewWiggleWidget() edit := ui.NewQLineEdit() vbox.AddWidget(dlg.widdly) vbox.AddWidget(edit) edit.OnTextChanged(func(text string) { dlg.widdly.SetText(text) }) edit.SetText("Hello World!") dlg.ResizeWithWidthHeight(360, 145) dlg.SetWindowTitle("Wiggly") return dlg }