Example #1
0
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
}
Example #2
0
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()
}
Example #3
0
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()
}