Example #1
0
func (p *MainWindow) Init() *MainWindow {
	if p.Widget.Init() == nil {
		return nil
	}
	p.SetWindowTitle("MainWindow")

	p.tab = qt5.NewTabWidget()

	p.tab.AddTab(p.createStdTab(), "Standard", nil)
	p.tab.AddTab(p.createMyTab(), "Custom", nil)
	p.tab.AddTab(p.createToolBox(), "ToolBox", nil)

	p.sbar = qt5.NewStatusBar()

	menubar := qt5.NewMenuBar()
	menu := qt5.NewMenuWithTitle("&File")
	//menu.SetTitle("&File")
	menubar.AddMenu(menu)

	act := qt5.NewAction()
	act.SetText("&Quit")
	act.OnTriggered(func(bool) {
		p.Close()
	})
	ic := qt5.NewIconWithFile("images/close.png")
	//defer ic.Close()
	act.SetIcon(ic)
	menu.AddAction(act)

	toolBar := qt5.NewToolBar()
	toolBar.AddAction(act)
	toolBar.AddSeparator()
	cmb := qt5.NewComboBox()
	cmb.AddItem("test1")
	cmb.AddItem("test2")
	cmb.SetToolTip("ComboBox")
	cmbAct := toolBar.AddWidget(cmb)
	fmt.Println(cmbAct)

	vbox := qt5.NewVBoxLayout()
	vbox.SetMargin(0)
	vbox.SetSpacing(0)
	vbox.SetMenuBar(menubar)
	vbox.AddWidget(toolBar)
	vbox.AddWidget(p.tab)
	vbox.AddWidget(p.sbar)

	p.SetLayout(vbox)

	p.tab.OnCurrentChanged(func(index int) {
		p.sbar.ShowMessage("current: "+p.tab.TabText(index), 0)
	})

	systray := qt5.NewSystemTray()
	systray.SetContextMenu(menu)
	systray.SetIcon(ic)
	systray.SetVisible(true)
	systray.ShowMessage("hello", "this is a test", qt5.Information, 1000)
	ic2 := systray.Icon()
	fmt.Println(ic2)

	p.SetWindowIcon(ic2)

	return p
}
Example #2
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()
}