-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqt.go
60 lines (49 loc) · 1.04 KB
/
qt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package gui
import (
"fmt"
"github.com/visualfc/goqt/ui"
"os"
)
var channel = make(chan bool)
func ExampleQt() {
ui.RunEx(os.Args, mainWindow)
}
func mainWindow() {
//first button
buttonOne := ui.NewPushButton()
buttonOne.SetText("First Button")
buttonTwo := ui.NewPushButton()
buttonTwo.SetText("Clear")
//Create a text box
textBox := ui.NewPlainTextEdit()
textBox.SetReadOnly(true)
textBox.AppendPlainText("Can you try the buttons?")
go listenButton(textBox)
//if buttonOne clicked
buttonOne.OnClicked(func() {
channel <- true
})
buttonTwo.OnClicked(func() {
textBox.Clear()
})
//create horizontal row
hbox := ui.NewHBoxLayout()
hbox.AddWidget(buttonOne)
hbox.AddWidget(buttonTwo)
//create vertical lines
vbox := ui.NewVBoxLayout()
vbox.AddLayout(hbox)
vbox.AddWidget(textBox)
//Show the elements on the window
widget := ui.NewWidget()
widget.SetLayout(vbox)
widget.Show()
}
func listenButton(edit *ui.QPlainTextEdit) {
i := 0
for {
<-channel
i++
edit.AppendPlainText(fmt.Sprintf("Clicked -- %d", i))
}
}