func main() { qt5.Main(func() { w := qt5.NewWidget() w.OnPaintEvent(func(e *qt5.PaintEvent) { paint := qt5.NewPainter() defer paint.Close() paint.Begin(w) pen := qt5.NewPen() pen.SetColor(color.RGBA{255, 128, 0, 0}) pen.SetWidth(2) fmt.Println(pen, pen.Color(), pen.Width()) paint.SetPen(pen) brush := qt5.NewBrush() brush.SetStyle(qt5.SolidPattern) brush.SetColor(color.RGBA{128, 128, 0, 255}) paint.SetBrush(brush) paint.DrawRect(qt5.Rect{10, 10, 100, 100}) }) w.SetSize(qt5.Size{400, 400}) w.Show() qt5.Run() }) }
func ui_main() { w := qt5.NewWidget() w.SetWindowTitle(qt5.Version()) w.SetSizev(300, 200) defer w.Close() w.Show() <-exit }
func main() { qt5.Main(func() { w := qt5.NewWidget() w.SetWindowTitle(qt5.Version()) w.SetSizev(300, 200) defer w.Close() w.Show() qt5.Run() }) }
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 new_window(w *backend.Window) { log4go.Debug("new_window entered") defer log4go.Debug("new_window exited") qw := qt5.NewWidget() qw.Show() qw.SetSizev(600, 400) tw := qt5.NewTabWidget() lbox := qt5.NewVBoxLayout() lbox.AddWidget(tw) c := newQLimeView(backend.GetEditor().Console()) sa := qt5.NewScrollArea() sa.SetWidget(c) lbox.AddWidget(sa) qw.SetLayout(lbox) wnds[w] = QLimeWindow{tw, 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 ui_main() { w := qt5.NewWidget() defer w.Close() list := qt5.NewListWidget() vbox := qt5.NewVBoxLayout() vbox.AddWidget(list) w.SetLayout(vbox) go func() { list.OnCurrentItemChanged(func(item, old *qt5.ListWidgetItem) { go func() { fmt.Println(item.Attr("text")) }() }) item := qt5.NewListWidgetItem() item.SetText("Item1") list.AddItem(item) list.AddItem(qt5.NewListWidgetItemWithText("Item2")) }() w.Show() qt5.Run() }
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() defer w.Close() w.SetWindowTitle("Rose") rose := qt5.NewWidget() rose.SetMinimumSize(qt5.Sz(510, 510)) img := qt5.NewImageWithSize(500, 500) defer img.Close() imgPainter := qt5.NewPainterWithImage(img) imgPainter.InitFrom(rose) defer imgPainter.Close() var timerid int = -1 var count int var timerValue int = 50 rose.OnTimerEvent(func(e *qt5.TimerEvent) { if e.TimerId() == timerid { draw(imgPainter) rose.Update() count++ if count >= max { w.KillTimer(timerid) } w.SetWindowTitle(fmt.Sprintf("Rose: %d*1e4", count)) } }) rose.OnPaintEvent(func(e *qt5.PaintEvent) { painter := qt5.NewPainter() defer painter.Close() painter.Begin(rose) painter.DrawImageEx(qt5.Point{0, 0}, img, img.Rect()) painter.End() }) load := func() { if timerid != -1 { rose.KillTimer(timerid) } for k, _ := range m { delete(m, k) } img.Fill(rgb(255, 255, 255)) count = 0 timerid = rose.StartTimer(timerValue) } stop := func() { rose.KillTimer(timerid) timerid = -1 } vbox := qt5.NewVBoxLayout() hbox := qt5.NewHBoxLayout() vbox.AddWidget(rose) vbox.AddLayout(hbox) loadBtn := qt5.NewButtonWithText("Reload") stopBtn := qt5.NewButtonWithText("Stop") exitBtn := qt5.NewButtonWithText("Exit") timerLabel := qt5.NewLabelWithText("Timer: 50 ") timerSlider := qt5.NewSlider() timerSlider.SetRange(1, 600) timerSlider.SetValue(50) timerSlider.OnValueChanged(func(v int) { timerValue = v timerLabel.SetText(fmt.Sprintf("Timer:%4d ", v)) }) maxLabel := qt5.NewLabelWithText("Max: 1024 ") maxSlider := qt5.NewSlider() maxSlider.SetRange(10, 10240) maxSlider.SetValue(1024) maxSlider.OnValueChanged(func(v int) { max = v maxLabel.SetText(fmt.Sprintf("Max:%5d ", v)) }) hbox.AddWidget(maxLabel) hbox.AddWidget(maxSlider) hbox.AddSpacing(10) hbox.AddWidget(timerLabel) hbox.AddWidget(timerSlider) hbox.AddSpacing(10) hbox.AddWidget(loadBtn) hbox.AddWidget(stopBtn) hbox.AddStretch(0) hbox.AddWidget(exitBtn) loadBtn.OnClicked(load) stopBtn.OnClicked(stop) exitBtn.OnClicked(func() { w.Close() }) w.SetLayout(vbox) w.Show() w.OnCloseEvent(func(e *qt5.CloseEvent) { rose.KillTimer(timerid) }) load() qt5.Run() }
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() }
func newQLimeView(v *backend.View) *QLimeView { log4go.Debug("new_QLimeView entered") defer log4go.Debug("new_QLimeView exited") var ret QLimeView ret.Widget = qt5.NewWidget() ret.v = v ret.Widget.OnPaintEvent(func(ev *qt5.PaintEvent) { p := qt5.NewPainter() defer p.Close() p.Begin(ret) b := v.Buffer() ps := p.Font().PointSize() pen := qt5.NewPen() p.SetPen(pen) brush := qt5.NewBrush() brush.SetStyle(qt5.SolidPattern) def := scheme.Settings[0] p.SetBrush(brush) f := p.Font() f.SetFixedPitch(true) p.SetFont(f) brush.SetColor(color.RGBA(def.Settings["background"])) p.DrawRect(ev.Rect()) is_widget, ok := v.Settings().Get("is_widget", false).(bool) is_widget = ok && is_widget pen.SetColor(color.RGBA(def.Settings["background"])) p.SetPen(pen) for y := 0; y < 20; y++ { pos := b.TextPoint(y, 0) line := b.Line(pos) if is_widget { p.DrawText(qt5.Point{0, (y + 1) * (ps + 2)}, b.Substr(line)) } else { for line.Contains(pos) { scope := primitives.Region{pos, pos} sn := v.ScopeName(pos) for line.Contains(pos) { pos++ if v.ScopeName(pos) != sn { scope.B = pos break } } is := line.Intersection(scope) c := color.RGBA(def.Settings["foreground"]) s := scheme.ClosestMatchingSetting(sn) if v, ok := s.Settings["foreground"]; ok { c = color.RGBA(v) } pen.SetColor(c) p.SetPen(pen) _, col := b.RowCol(line.A) p.DrawText(qt5.Point{col * ps / 2, (y + 1) * (ps + 2)}, b.Substr(is)) line.A = is.End() } } } }) ret.Widget.OnResizeEvent(func(ev *qt5.ResizeEvent) { if w, ok := v.Settings().Get("is_widget", false).(bool); ok && !w { ret.Widget.SetMinimumSize(qt5.Size{600, 100}) } }) v.Settings().Set("lime.qt.widget", &ret) return &ret }