usr bin env ruby KCODE UTF-8 require Qt4 require mainwindow rb class M

 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
#!/usr/bin/env ruby
$KCODE = 'UTF-8'
require 'Qt4'
require 'mainwindow.rb'
class Main_Window < Qt::MainWindow
def initialize parent = nil
super
@ui = Ui_MainWindowClass.new
@ui.setupUi(self)
end
def draw_graph
@graph = Qt::GraphicsScene.new
@nodes = []
@node = Node.new(0, 0)#, "A", Qt::black)
#puts @graph.methods
#puts methods#@graphicsView
@ui.graphicsView.setScene(@graph)
@graph.addItem(@node)
#grap#
#puts self.graphicsView.methods
#puts graphicsView.methods#.setScene(@graph)
end
end
class Node < Qt::GraphicsItem
def initialize(xpos, ypos)#, title, color)
@xpos, @ypos, @title, @color = xpos, ypos, "A", Qt::black#title, color
end
def paint(painter, option, widget)
painter.setBrush(Qt::black)
painter.drawEllipse(-5+@xpos, -5+@ypos, 10, 10)
painter.drawText(@xpos+5,@ypos-5,@title)
painter.setBrush(Qt::blue)
painter.setPen(Qt::blue)
painter.drawText(@xpos-5,@ypos-5,@mark)
end
end
def main
app = Qt::Application.new(ARGV)
ui = Main_Window.new
#window = Qt::MainWindow.new
window = Main_Window.new
window.draw_graph
#ui.setupUi(window)
window.show
app.exec()
end
main