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