コード例 #1
0
ファイル: widgets.go プロジェクト: Kelimion/go-qt5
func ui_main() {
	exit := make(chan bool)
	go func() {
		fmt.Println("vfc/ui")
		qt5.OnInsertObject(func(v interface{}) {
			fmt.Println("add item", v)
		})
		qt5.OnRemoveObject(func(v interface{}) {
			fmt.Println("remove item", v)
		})
		w := new(MainWindow).Init()
		defer w.Close()

		w.SetSizev(400, 300)
		w.OnCloseEvent(func(e *qt5.CloseEvent) {
			fmt.Println("close", e)
		})
		w.Show()
		<-exit
	}()
	qt5.Run()
	exit <- true
}
コード例 #2
0
ファイル: attrs.go プロジェクト: 2105666566/go-qt5
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
}
コード例 #3
0
ファイル: dock.go プロジェクト: 2105666566/go-qt5
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()
}