Development/Tutorials/Qt4 Ruby Tutorial/Chapter 05

From KDE TechBase
Revision as of 01:43, 30 December 2009 by Alisha (talk | contribs) (Created page with '{{Template:I18n/Language Navigation Bar|Development/Tutorials/Qt4 Ruby Tutorial/Chapter 05}} {{TutorialBrowser| series=[[Development/Tutorials/Qt4_Ruby_Tutorial|Qt4 Ruby Tutori...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


Development/Tutorials/Qt4 Ruby Tutorial/Chapter 05


Building Blocks
Tutorial Series   Qt4 Ruby Tutorial
Previous   Tutorial 4 -Calling it Quits
What's Next   Tutorial 6 - Let There Be Widgets
Further Reading   n/a

Building Blocks

Files:

Overview

This example shows how to create and connect together several widgets by using signals and slots, and how to handle resizes.

require 'Qt4'

class MyWidget < Qt::Widget

 def initialize()
   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()
   layout.addWidget(quit)
   layout.addWidget(lcd)
   layout.addWidget(slider)
   setLayout(layout)
 end

end

app = Qt::Application.new(ARGV)

widget = MyWidget.new()

widget.show() app.exec()

Line by Line Walkthrough