-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.rb
99 lines (77 loc) · 2.31 KB
/
widget.rb
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require 'Qt4'
class MyWidget < Qt::Widget
def initialize(parent = nil)
super()
# quit = Qt::PushButton.new('Quit')
# quit.setFont(Qt::Font.new('Times', 18, Qt::Font::Bold))
# lcd = Qt::LCDNumber.new(2)
# slider = Qt::Slider.new(Qt::Horizontal)
# slider.setRange(0, 99)
# slider.setValue(0)
# connect(quit, SIGNAL('clicked()'), $qApp, SLOT('quit()'))
# connect(slider, SIGNAL('valueChanged(int)'), lcd, SLOT('display(int)'))
# layout = Qt::VBoxLayout.new(self)
# layout.addWidget(quit)
# layout.addWidget(lcd)
# layout.addWidget(slider)
# setLayout(layout)
setWindowTitle(__FILE__)
setToolTip("This is MyWidget")
init_folder_ui
end
def center
qdw = Qt::DesktopWidget.new
screenWidth = qdw.width
screenHeight = qdw.height
x = (screenWidth - width()) / 2
y = (screenHeight - height()) / 2
move x, y
end
def init_folder_ui
grid = Qt::GridLayout.new self
nameLabel = Qt::Label.new "Name", self
nameEdit = Qt::LineEdit.new self
text = Qt::TextEdit.new self
okButton = Qt::PushButton.new "OK", self
closeButton = Qt::PushButton.new "Close", self
grid.addWidget nameLabel, 0, 0
grid.addWidget nameEdit, 0, 1, 1, 3
grid.addWidget text, 1, 0, 2, 4
grid.setColumnStretch 1, 1
grid.addWidget okButton, 4, 2
grid.addWidget closeButton, 4, 3
end
def init_v_h_ui
windLabel = Qt::Label.new "Windows", self
edit = Qt::TextEdit.new self
edit.setEnabled false
activate = Qt::PushButton.new "Activate", self
close = Qt::PushButton.new "Close", self
help = Qt::PushButton.new "Help", self
ok = Qt::PushButton.new "OK", self
vbox = Qt::VBoxLayout.new self do
addWidget windLabel
hbox1 = Qt::HBoxLayout.new do
addWidget edit
vbox1 = Qt::VBoxLayout.new do
addWidget activate
addWidget close, 0, Qt::AlignTop
end
addLayout vbox1
end
addLayout hbox1
hbox2 = Qt::HBoxLayout.new do
addWidget help
addStretch 1
addWidget ok
end
addLayout hbox2, 1
end
setLayout vbox
end
end
app = Qt::Application.new(ARGV)
widget = MyWidget.new()
widget.show()
widget.center()
app.exec()