Пример #1
0
func ui_main() {
	w := qt5.NewWidget()

	defer w.Close()
	list := qt5.NewListWidget()
	item := qt5.NewListWidgetItem()
	item.SetText("Item1")
	list.AddItem(item)
	list.AddItem(qt5.NewListWidgetItemWithText("Item2"))

	button1 := qt5.NewButton()
	button1.SetText("Нажми меня")
	button2 := qt5.NewButtonWithText("Изменить стиль фрейма")

	var sz qt5.Size
	sz.Height = 35
	sz.Width = 300
	frame := qt5.NewFrame()
	frame.SetMinimumSize(sz)
	button1.SetParent(frame)
	button2.SetParent(frame)
	button1.SetPosv(5, 5)
	button2.SetPosv(100, 5)

	vbox := qt5.NewVBoxLayout()
	vbox.AddWidget(frame)
	vbox.AddWidget(list)

	w.SetLayout(vbox)
	style := 1
	go func() {
		button1.OnClicked(func() {
			fmt.Println("Clicked")
			button1.SetText("Hello")
			list.AddItem(qt5.NewListWidgetItemWithText("Привет"))
		})
		button2.OnClicked(func() {
			fmt.Println(style)
			frame.SetFrameStyle(style)
			style++
			if style == 7 {
				style = 0
			}
		})
		list.OnCurrentItemChanged(func(item, old *qt5.ListWidgetItem) {
			//go func() {
			fmt.Println(item.Attr("text"))
			//}()
		})

	}()
	w.Show()

	qt5.Run()
}
Пример #2
0
func ui_main() {
	//main window
	w := qt5.NewWidget()
	defer w.Close()
	w.SetGeometryv(10, 10, 500, 500)

	button2 := qt5.NewButtonWithText("Добавить вкладку")
	button2.SetSizePolicyHV(0, 0)
	//create verical layout
	vbox := qt5.NewVBoxLayout()

	vbox.AddWidget(button2)

	//create table
	table := qt5.NewTableWidget()
	table.SetRowCount(10)
	table.SetColumnCount(10)

	tab := qt5.NewTabWidget()
	var icon qt5.Icon
	tab.AddTab(table, "вкладка", &icon)
	vbox.AddWidget(tab)
	w.SetLayout(vbox)
	num := 1
	//var ti *qt5.TableWidgetItem

	go func() {

		button2.OnClicked(func() {
			lab := strconv.Itoa(num)
			tab.AddTab(qt5.NewFrame(), "вкладка "+lab, &icon)
			num++

		})

		table.OnCellActivated(func(row int, column int) {
			fmt.Printf("row=%d column=%d \n", row, column)
			curit := table.Item(row, column)
			if curit == nil {
				ti := qt5.NewTableWidgetItem()
				ti.SetText("NewItem")
				table.SetItem(row, column, ti)
			} else {
				curit.SetText("ItemExist")
			}
		})

	}()
	w.Show()

	qt5.Run()
}
Пример #3
0
func ui_main() {
	w := qt5.NewWidget()
	defer w.Close()
	w.SetGeometryv(10, 10, 500, 200)

	chkbox := qt5.NewCheckBoxWithText("Таймер вкл/выкл")
	chkbox.SetSizePolicyHV(0, 0)
	timer := qt5.NewTimer()
	timer.SetInterval(100)
	timelab := qt5.NewLabelWithText("0")
	timelab.SetFrameStyle(1)

	timelab.SetSizePolicyHV(0, 0)

	progress := qt5.NewScrollBar()
	progress.SetRange(0, 100)
	progress.SetEnabled(false)

	slide1 := qt5.NewSlider()
	slide1.SetRange(0, 100)

	label1 := qt5.NewLabelWithText("0    ")
	label1.SetSizePolicyHV(0, 0)
	//chkbox.SetSizePolicyHV(0, 0)
	//var sz qt5.Size 	sz.Height = 300 	sz.Width = 300
	hbox := qt5.NewHBoxLayout()
	vbox := qt5.NewVBoxLayout()

	hbox.AddWidget(progress)
	hbox.AddWidget(chkbox)
	hbox.AddWidget(timelab)

	vbox.AddLayout(hbox)
	vbox.AddWidget(slide1)
	vbox.AddWidget(label1)
	w.SetLayout(vbox)
	num := 0

	go func() {

		chkbox.OnStateChanged(func(st int) {
			fmt.Printf("State changed on %d \n", st)
			if st == 2 {
				timer.Start()
			}
			if st == 0 {
				timer.Stop()
			}

		})
		timer.OnTimeout(func() {
			fmt.Printf("Time=%d \n", num)
			timelab.SetText(strconv.Itoa(num))
			num = num + 1
			progress.SetSliderPosition(num)

			if num == 100 {
				num = 0
			}
		})
		slide1.OnValueChanged(func(val int) {
			label1.SetText(strconv.Itoa(val))
		})

	}()
	w.Show()

	qt5.Run()
}