LEDs make prettier applications
When making GUI apps, one ‘trick’ to providing some nice user feedback is to use a LED to demonstrate some kind of on/off state. LED is a bit of a misnomer here, since we’re not really using diodes, but I think you get the idea.
Here’s a quick QtRuby LED class we can use.
require 'Qt'
class MyLED < Qt::Frame
slots 'setOn(bool), emergency()'
def setOn(on)
if(on)
setPaletteBackgroundColor(Qt::green)
else
setPaletteBackgroundColor(Qt::darkGreen)
end
def emergency
setPaletteBackgroundColor(Qt::red)
end
end
With this class in our application we can use it to provide some kind of feedback that something is on/off, or that there is a problem.
app = Qt::Application.new(ARGV)
layout = Qt::VBox.new(nil)
layout.setMinimumSize(100,50)
led = MyLED.new(layout)
label = Qt::Label.new("Status",layout)
label.setAlignment(Qt::AlignCenter)
app.setMainWidget(layout)
layout.show
app.exec
Now our event loop has started and we’d normally use signals and slots to activate the LED, but I’m going to do it by hand for demonstration purposes. If I insert this before the last line in the previous example:
led.setOn(true)
We get an activated LED:

Similarly:
led.setOn(false)
leads to

And we can also give some feedback that something critically wrong has happened:
led.emergency

Many other color possibilities exist as well.
—-
Want to learn more? See my book Rapid GUI Development with QtRuby to learn how to make GUI applications with Ruby.