Development/Tutorials/Qt4 Ruby Tutorial/Chapter 05

Development | Tutorials | Qt4 Ruby Tutorial
Revision as of 02:43, 30 December 2009 by Alisha (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Contents

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

Qt4 Ruby Tutorial Screenshot 5.png

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


KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal