Below is source of basic window with TreeWidget on left and TabWidget on
the right. I stopped here because there is no way I can get
itemActivated() signal to call my nitem_clicked method. I have tried
practically everything I could find on net (there is very little Qt Ruby
examples beyond basics). Current source shows the most complicated
option, that I could have found ;-(
ruby 1.9.3
qtbindings (4.6.3.4)
kubuntu 10.4
by
TheR
require ‘Qt’
class TreeView < Qt::TreeWidget
slots ‘nitem_clicked(TreeWidgetItem*, int)’
##############################################
def initialize
super
init_ui
end
##############################################
def init_ui
self.header_hidden = true
item = Qt::TreeWidgetItem.new
item.setText(0,‘Mongo’)
addTopLevelItem(item)
item = Qt::TreeWidgetItem.new #Qt::TreeViewItem.new()
item.setText(0,’++ add new Mongo database’)
addTopLevelItem(item)
connect(self, SIGNAL(‘itemActivated( TreeWidgetItem*, int )’), self,
SLOT(‘nitem_clicked(TreeWidgetItem*, int)’))
end
#############################################
def nitem_clicked(item, column)
p item.inspect
end
end
##########################################
Main app
##########################################
class QtApp < Qt::MainWindow
def initialize
super
init_ui
resize 800, 600
move 300, 300
show
end
#############################################
def init_ui
splitter = Qt::Splitter.new
mongo_tree = TreeView.new
splitter.addWidget mongo_tree
mongo_tabs = Qt::TabWidget.new self
tab = Qt::Widget.new
mongo_tabs.addTab tab, ‘Tab1’
splitter.addWidget mongo_tabs
setCentralWidget splitter
quit = Qt::Action.new “&Quit”, self
file = menuBar.addMenu “&File”
file.addAction quit
self.connect(quit, SIGNAL(“triggered()”), Qt::Application.instance,
SLOT(“quit()”))
end
end
app = Qt::Application.new ARGV
QtApp.new
app.exec