Example #1
0
func (p *MainWindow) createToolBox() qt5.IWidget {
	tb := qt5.NewToolBox()
	tb.AddItem(qt5.NewButtonWithText("button"), "btn", nil)
	tb.AddItem(qt5.NewLabelWithText("Label\nInfo"), "Label", nil)
	pixmap := qt5.NewPixmapWithFile("images/liteide128.png")
	//defer pixmap.Close()
	lbl := qt5.NewLabel()
	lbl.SetPixmap(pixmap)
	tb.AddItem(lbl, "Lalel Pixmap", nil)
	buf, err := ioutil.ReadFile("images/liteide128.png")
	if err == nil {
		pixmap2 := qt5.NewPixmapWithData(buf)
		tb.AddItem(qt5.NewLabelWithPixmap(pixmap2), "Lalel Pixmap2", nil)
	}
	return tb
}
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 main_ui() {
	qt5.OnInsertObject(func(v interface{}) {
		fmt.Println("add item", v)
	})
	qt5.OnRemoveObject(func(v interface{}) {
		fmt.Println("remove item", v)
	})
	w := qt5.NewMainWindow()
	defer w.Close()
	go func() {
		dock := qt5.NewDockWidgetWithTitle("Dock")
		dock.SetDock(qt5.NewButtonWithText("Hello"))
		w.AddDockWidget(qt5.LeftDockWidgetArea, dock)
		btn := qt5.NewButtonWithText("HideDock")
		w.SetCentralWidget(btn)
		w.SetSize(qt5.Sz(200, 200))

		tb := qt5.NewToolBarWithTitle("Standard")
		tb.AddWidget(qt5.NewButtonWithText("ok"))
		w.AddToolBar(tb)

		tb.OnCloseEvent(func(e *qt5.CloseEvent) {
			fmt.Println("tb close", e)
		})
		sb := qt5.NewStatusBar()
		w.SetStatusBar(sb)
		sb.OnCloseEvent(func(e *qt5.CloseEvent) {
			fmt.Println("sb close", e)
		})

		btn.OnClicked(func() {
			dock.Hide()
			runtime.GC()
			btn.SetText(btn.Text())
		})
		dock.OnCloseEvent(func(e *qt5.CloseEvent) {
			fmt.Println(e)
		})

		go func() {
			for {
				timer := time.NewTimer(1)
				select {
				case <-timer.C:
					btn.SetText(btn.Text())
					btn.SetText(btn.Text())
					btn.SetText(btn.Text())
					fmt.Println(">", btn.Text())
					if btn.Text() != "HideDock" {
						panic("close")
					}
				}
			}
		}()

		dock.OnVisibilityChanged(func(b bool) {
			fmt.Println(b)
			if !b {
				time.AfterFunc(1e9, func() {
					if dock.IsValid() {
						dock.Show()
					}
				})
			}
		})

		w.Show()
	}()

	qt5.Run()
}