Ruby Qt/KDE4 Template KMainWindow

![KMainWindow](<%= site_url %>/images/kmainwindow.png “KMainWindow”){: .pull-right} Starting using the Qt-Toolkit (or the extension with KDE classes) is a little difficult. Especially if you never used really the toolkit with C++. So you have to learn translating the C++ API reference into ruby.

Some usefull links:

But when you got it, the usage is pretty cool. In the following code listing you can find the code for a full-featured kmainwindow.

#!/usr/bin/env ruby
# file: kmainwindow.rb
$KCODE = 'u'

require 'korundum4' # kd4 bindings

class CustomWidget < KDE::MainWindow

  def initialize


    resize(520, 535)

    # Prepare the Actions
    @actionQuit = self ) {
      setIcon "application-exit"
    connect( @actionQuit, SIGNAL( :triggered ), SLOT( :close ) )

    # Prepare the Menu
    @menuBar = menuBar
    @menuFile = @menuBar
    @menuFile.addAction @actionQuit
    @menuBar.addAction @menuFile.menuAction
    @helpMenu = helpMenu
    @menuBar.addAction @helpMenu.menuAction


    # Prepare Statusbar
    @statusBar = statusBar
    setStatusBar @statusBar

    # Prepare Toolbar
    @toolBar = toolBar
    @toolBar.addAction @actionQuit
    addToolBar(Qt::TopToolBarArea, @toolBar)

    # Prepare Central Widget
    @centralwidget = self
    setCentralWidget @centralwidget


  def retranslateUi
    @menuFile.title = i18n "File"
    setWindowTitle i18n "MainWindow"
    # @statusBar.showMessage i18n "Loading"
    @actionQuit.text = i18n "Quit"
    @actionQuit.shortcut = i18nc( "Quit", "Ctrl+Q" )


about =
  "app",                           # internal application name
  # language catlog name for i10n (konqueror's catalog for the beginning is better than no catalog)
  KDE.ki18n("KApp"),                 # application name in the about menu and everywhere else
  "0.1",                             # application version
  KDE::ki18n("A Tool to easily create HTML formatted Code"),  # short description
  KDE::AboutData::License_GPL_V3,    # license
  KDE::ki18n("(c) 1999-2000, Name"), # copyright info
  # text in the about box - maybe with \n line breaks
  KDE::ki18n("just some text in the about box"),
  # project homepage and eMail adress for bug reports - attention: homepage changes standard dbus/dcop name!
  "", "" )

about.setProgramIconName  "plasma" # use the plasma-icon instead of question mark
KDE::CmdLineArgs.init(ARGV, about)
a =
w =
a.topWidget = w