Qtラボジャパン Qtをはじめよう!第13回:GUIデザイナを使おう をQtRubyでやります。
Qt Creator 2.0.1で作ります。但し'close'は'クローズ'でボタンとしました。
C:\Qt\tkwork\example2>rbuic4 example.ui -x -o ui_example.rb
main.rbとexample.rbはコーディング(utf-8n)します。
C:\Qt\tkwork\example2>ruby -Ku main.rb
#main.rb
require 'rubygems'
require 'Qt4'
require 'example.rb'
app = Qt::Application.new(ARGV)
example = Example.new
example.show
app.exec
#example.rb
require 'ui_example.rb'
class Example <>
def initialize(parent = nil)
super
@ui = Ui_Example.new
@ui.setupUi(self)
connect(@ui.button, SIGNAL('clicked()'), $qApp, SLOT('quit()'))
end
end
#ui_example.rb
=begin
** Form generated from reading ui file 'example.ui'
**
** Created: 木 10 7 01:00:48 2010
** by: Qt User Interface Compiler version 4.6.1
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
=end
require 'Qt4'
class Ui_Example
attr_reader :verticalLayout
attr_reader :slider
attr_reader :button
def setupUi(example)
if example.objectName.nil?
example.objectName = "example"
end
example.resize(102, 68)
@verticalLayout = Qt::VBoxLayout.new(example)
@verticalLayout.spacing = 6
@verticalLayout.margin = 11
@verticalLayout.objectName = "verticalLayout"
@slider = Qt::Slider.new(example)
@slider.objectName = "slider"
@slider.orientation = Qt::Horizontal
@verticalLayout.addWidget(@slider)
@button = Qt::PushButton.new(example)
@button.objectName = "button"
@verticalLayout.addWidget(@button)
retranslateUi(example)
Qt::MetaObject.connectSlotsByName(example)
end # setupUi
def setup_ui(example)
setupUi(example)
end
def retranslateUi(example)
example.windowTitle = Qt::Application.translate("Example", "Example", nil, Qt::Application::UnicodeUTF8)
@button.text = Qt::Application.translate("Example", "\343\203\227\343\203\203\343\202\267\343\203\245", nil, Qt::Application::UnicodeUTF8)
end # retranslateUi
def retranslate_ui(example)
retranslateUi(example)
end
end
module Ui
class Example <>
end
end # module Ui
if $0 == __FILE__
a = Qt::Application.new(ARGV)
u = Ui_Example.new
w = Qt::Widget.new
u.setupUi(w)
w.show
a.exec
end
C:\Qt\tkwork\example2>rbuic4 example.ui -x -o ui_example.rb
main.rbとexample.rbはコーディング(utf-8n)します。
C:\Qt\tkwork\example2>ruby -Ku main.rb
#main.rb
require 'rubygems'
require 'Qt4'
require 'example.rb'
app = Qt::Application.new(ARGV)
example = Example.new
example.show
app.exec
#example.rb
require 'ui_example.rb'
class Example <>
def initialize(parent = nil)
super
@ui = Ui_Example.new
@ui.setupUi(self)
connect(@ui.button, SIGNAL('clicked()'), $qApp, SLOT('quit()'))
end
end
#ui_example.rb
=begin
** Form generated from reading ui file 'example.ui'
**
** Created: 木 10 7 01:00:48 2010
** by: Qt User Interface Compiler version 4.6.1
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
=end
require 'Qt4'
class Ui_Example
attr_reader :verticalLayout
attr_reader :slider
attr_reader :button
def setupUi(example)
if example.objectName.nil?
example.objectName = "example"
end
example.resize(102, 68)
@verticalLayout = Qt::VBoxLayout.new(example)
@verticalLayout.spacing = 6
@verticalLayout.margin = 11
@verticalLayout.objectName = "verticalLayout"
@slider = Qt::Slider.new(example)
@slider.objectName = "slider"
@slider.orientation = Qt::Horizontal
@verticalLayout.addWidget(@slider)
@button = Qt::PushButton.new(example)
@button.objectName = "button"
@verticalLayout.addWidget(@button)
retranslateUi(example)
Qt::MetaObject.connectSlotsByName(example)
end # setupUi
def setup_ui(example)
setupUi(example)
end
def retranslateUi(example)
example.windowTitle = Qt::Application.translate("Example", "Example", nil, Qt::Application::UnicodeUTF8)
@button.text = Qt::Application.translate("Example", "\343\203\227\343\203\203\343\202\267\343\203\245", nil, Qt::Application::UnicodeUTF8)
end # retranslateUi
def retranslate_ui(example)
retranslateUi(example)
end
end
module Ui
class Example <>
end
end # module Ui
if $0 == __FILE__
a = Qt::Application.new(ARGV)
u = Ui_Example.new
w = Qt::Widget.new
u.setupUi(w)
w.show
a.exec
end
0 件のコメント:
コメントを投稿