func NewCodeEdit() *CodeEdit { w := &CodeEdit{} w.QWidget = ui.NewQWidget() w.edit = ui.NewQPlainTextEdit() w.edit.SetLineWrapMode(ui.QPlainTextEdit_NoWrap) w.syntax = ui.NewQSyntaxHighlighterHookWithDoc(w.edit.Document()) w.lineArea = ui.NewQWidget() w.lineArea.SetFixedWidth(0) hbox := ui.NewQHBoxLayout() hbox.SetMargin(0) hbox.SetSpacing(0) hbox.AddWidget(w.lineArea) hbox.AddWidget(w.edit) w.SetLayout(hbox) w.lineArea.InstallEventFilter(w) w.edit.OnBlockCountChanged(func(int32) { w.UpdateLineNumberAreaWidth() w.lineArea.Update() }) w.edit.OnUpdateRequest(func(*ui.QRect, int32) { w.lineArea.Update() }) w.UpdateLineNumberAreaWidth() w.MakeRules() w.syntax.OnHighlightBlock(w.OnHighlightBlock) font := w.edit.Font() font.SetPointSize(12) w.edit.SetFont(font) w.lineArea.SetFont(font) return w }
func main() { ui.Run(func() { info := fmt.Sprintf("GoQt Version %v \nQt Version %v\ngo verison %v %v/%v", ui.Version(), ui.QtVersion(), runtime.Version(), runtime.GOOS, runtime.GOARCH) lable := ui.NewQLabel() lable.SetText(info) hbox := ui.NewQHBoxLayout() hbox.AddWidget(lable) widget := ui.NewQWidget() widget.SetLayout(hbox) widget.Show() }) }
func NewWiggleWidget() *WigglyWidget { w := &WigglyWidget{ui.NewQWidget(), 0, "Hello World", make(chan bool)} w.SetBackgroundRole(ui.QPalette_Midlight) w.SetAutoFillBackground(true) font := w.Font() font.SetPointSize(font.PointSize() + 20) w.SetFont(font) w.InstallEventFilter(w) t := ui.NewQTimer() t.SetInterval(60) t.OnTimeout(func() { w.step++ w.Update() }) t.Start() return w }
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 main() { ui.Run(func() { widget := ui.NewQWidget() widget.Show() }) }