In the previous article, I introduce thee way to rebuild portupgrade to use Ruby 1.9 on PC-BSD. By the way, on PC-BSD, there are two more libraries that depend on ruby 1.8 - Korundum and QtRuby. So that I introduce the way to rebuild these to use Ruby 1.9.
Showing posts with label QtRuby. Show all posts
Showing posts with label QtRuby. Show all posts
Saturday, January 21, 2012
Monday, August 9, 2010
What version of Qt and QtRuby are bundled on openSUSE 11.3?
I check what version of Qt and QtRuby are bundled on openSUSE 11.3 like this entry. And the results are below:
> rbrcc -version Ruby Resource Compiler for Qt version 4.6.3 > rbuic4 -v Qt User Interface Compiler version 4.6.3 > rbqtapi -v QtRuby 2.1.0 using Qt-4.6.3QtRuby 2.1.0 is the latest trunk version.
Tuesday, February 2, 2010
Pan WebView
I add a sample program to my graphics-dojo clone repository - Pan WebView. Almost issues of this program are similar to ones of phosphorescence: Flickable color list, but there is new issue and easy solution.
It is cursor setting. Original C++ program set the Constant Qt::OpenHandCursor, but QtRuby must set like below:
Full code is here and execution result is below:
It is cursor setting. Original C++ program set the Constant Qt::OpenHandCursor, but QtRuby must set like below:
Qt::Application::override_cursor = Qt::Cursor.new(Qt::OpenHandCursor)
Full code is here and execution result is below:
Thursday, January 28, 2010
QtRuby Debug Level
If you want to know QtRuby internal behavior, let's set the "QtRuby Debug Level". Just write one line in the beginning of QtRuby file.
But I could not find the way to be on the debug level from ruby interpreter (e.g. command line options).
# Defualt (Off)Qt::DebugLevel::High is enough to know internal behavior.
Qt.debug_level = Qt::DebugLevel::Off
# Minimal
Qt.debug_level = Qt::DebugLevel::Minimal
# High
Qt.debug_level = Qt::DebugLevel::High
# Extensive
Qt.debug_level = Qt::DebugLevel::Extensive
But I could not find the way to be on the debug level from ruby interpreter (e.g. command line options).
Saturday, January 16, 2010
Flickable color list
I add a sample program to my graphics-dojo clone repository - Flickable color list. It was difficult in 3 points.
Saturday, November 21, 2009
Installing QtRuby on Ruby 1.9.1 from openSUSE source rpm
At 1st, install Ruby 1.9.1 with same instruction of this article:
phosphorescence: Install Ruby 1.9.1
Then I should go to install QtRuby with source from repository, but smoke/generator of QtRuby is still unstable yet as I had write in this article:
phosphorescence: Confusing about smoke/generator
So I decide to install from source RPM package of openSUSE 11.2 - my own environment.
phosphorescence: Install Ruby 1.9.1
Then I should go to install QtRuby with source from repository, but smoke/generator of QtRuby is still unstable yet as I had write in this article:
phosphorescence: Confusing about smoke/generator
So I decide to install from source RPM package of openSUSE 11.2 - my own environment.
Thursday, November 19, 2009
What version of Qt and QtRuby are bundled on openSUSE 11.2?
To see the version of Qt and qmake, type the command below:
And to see the version of QtRuby, familiar commands below:
> qmake --version QMake version 2.01a Using Qt version 4.5.3 in /usr/libQt on openSUSE 11.2 is version 4.5.3 ... latest stable version.
And to see the version of QtRuby, familiar commands below:
> rbrcc -version Ruby Resource Compiler for Qt version 4.5.3 > rbuic4 -v Qt User Interface Compiler version 4.5.3 > rbqtapi -v QtRuby 2.0.5 using Qt-4.5.3QtRuby on openSUSE 11.2 is version 2.0.5 ... it's trunk version.
Tuesday, October 6, 2009
Qt 4.5.3 was released
In the first day of this month, Qt 4.5.3 was released. I download and install Qt 4.5.3 SDK (LGPL) from here.
#./qt-sdk-linux-x86_64-opensource-2009.04.binInstallation instructions of QtRuby are below:
>cmake \ > -DCMAKE_INSTALL_PREFIX=/opt/ruby-1.9.1 \ > -DRUBY_EXECUTABLE=/opt/ruby-1.9.1/bin/ruby \ > -DRUBY_LIBRARY=/opt/ruby-1.9.1/lib/libruby.so.1.9.1 \ > -DRUBY_INCLUDE_PATH=/opt/ruby-1.9.1/include/ruby-1.9.1 \ > -DQT_QMAKE_EXECUTABLE=/opt/qtsdk-2009.04/qt/bin/qmake \ > -DQT_MKSPECS_DIR=/opt/qtsdk-2009.04/qt/mkspecs \ > -Wno-dev \ > -DENABLE_SMOKE=on \ > -DENABLE_QTRUBY=on \ > -DENABLE_QTWEBKIT_SMOKE=on \ > -DENABLE_QTSCRIPT_SMOKE=on \ > -DENABLE_QTUITOOLS_SMOKE=on \ > -DENABLE_QTTEST_SMOKE=off \ > -DENABLE_PHONON_SMOKE=off \ > -DENABLE_QSCI_SMOKE=off \ > -DENABLE_QWT_SMOKE=off \ > -DENABLE_KDE_SMOKE=off \ > -DENABLE_KDEVPLATFORM_SMOKE=off \ > -DENABLE_KHTML_SMOKE=off \ > -DENABLE_KTEXTEDITOR_SMOKE=off \ > -DENABLE_SOLID_SMOKE=off \ > -DENABLE_PLASMA_SMOKE=off \ > -DENABLE_QTWEBKIT_RUBY=on \ > -DENABLE_QTUITOOLS_RUBY=on \ > -DENABLE_QTSCRIPT=on \ > -DENABLE_QTTEST=off \ > -DENABLE_PHONON_RUBY=off \ > -DENABLE_QSCINTILLA_RUBY=off \ > -DENABLE_QWT_RUBY=off \ > -DENABLE_SOPRANO_RUBY=off \ > -DENABLE_KDEVPLATFORM_RUBY=off \ > -DENABLE_KORUNDUM_RUBY=off \ > -DENABLE_KHTML_RUBY=off \ > -DENABLE_KTEXTEDITOR_RUBY=off \ > -DENABLE_SOLID_RUBY=off \ > -DENABLE_KROSSRUBY=off \ > -DENABLE_PLASMA_RUBY=off \ > -DENABLE_QIMAGEBLITZ_SMOKE=offThen check QtRuby commands.
>/opt/ruby-1.9.1/bin/rbrcc -version Ruby Resource Compiler for Qt version 4.5.3 >/opt/ruby-1.9.1/bin/rbuic4 -v Qt User Interface Compiler version 4.5.3 >/opt/ruby-1.9.1/bin/rbqtapi -v QtRuby 2.0.3 using Qt-4.5.3And QtCreator of this installer was also updated to 1.2.1.
Monday, September 28, 2009
Confusing about smoke/generator
From several previous revision, QtRuby's and other kdebindings' code generation tool have been changed from kalyptus to smoke/generator. It's advantage to port kdebindings for non-Unix platforms: smoke/generator is based on C++ whereas kalyptus is based on Perl.
But now I'm confusing because smoke/generator fails after starting make immediately. There are message like below:
I have decided not following trunk of QtRuby in a while. I only use released version.
But now I'm confusing because smoke/generator fails after starting make immediately. There are message like below:
Cannot load library generator_smoke: (libgenerator_smoke.so: ...Unfortunately, it's not only problem for me. Others are encountering this problem. And fortunately, the author is succeeding on his each environments.
I have decided not following trunk of QtRuby in a while. I only use released version.
Friday, September 4, 2009
Pros and Cons of "Yet another UI File loading"
In last entry, I only introduced sample code of "Yet another UI File loading". In this post, I will write pros and cons of it.
Tuesday, September 1, 2009
Yet another UI File loading
In past entries, I wrote 2 normal approaches of loading UI file in QtRuby.
Today I introduce a little unusual approach.
In this approach, evaluate the output of rbuic4 command, and then use Module#const_get to instantiate top widget class and its parent class.
- rbuic4 command
phosphorescence: rbuic4 - qtuitools library
phosphorescence: Another usage of UI File from QtRuby #1
phosphorescence: Another usage of UI File from QtRuby #2
Today I introduce a little unusual approach.
require 'Qt4'
require 'rexml/document'
# define method instead of qtuiloader
def Qt.load_ruby_from_ui(file_path, rbuic4_command = 'rbuic4')
doc = REXML::Document.new(::File.new(file_path))
top_widget_name = REXML::XPath.first(doc, '/ui/class/text()').value
parent_name = REXML::XPath.first(doc, '/ui/widget/@class')
eval `#{rbuic4_command} #{file_path}`
top_widget = const_get("Ui_#{top_widget_name.gsub(/\A(\w)/) {$1.upcase}}").new
parent = Qt::const_get(parent_name.value.gsub(/\AQ/, '')).new
top_widget.setupUi(parent)
parent
end
Qt::Application.new(ARGV) do
window = Qt.load_ruby_from_ui(
'/opt/qtsdk-2009.03/qt/examples/widgets/stylesheet/layouts/default.ui',
'/opt/ruby-1.9.1/bin/rbuic4')
window.show
exec
end
In this approach, evaluate the output of rbuic4 command, and then use Module#const_get to instantiate top widget class and its parent class.
Tuesday, August 18, 2009
drag move charm #2
(continued from phosphorescence: drag move charm #1)
Why sample widget cannot be moved with grabbing top level widget? It's handled in DragMoveCharm#event_filter method. I had surveyed and debugged this method. Then I found it is caused by incorrect decision of inheritance. See the example code:
After QtRuby 2.0.3, class method Module.ancestors returns not only Ruby's super classes but also Qt's super classes because Qt::Base class overrides this method. But, other related methods don't. Object#is_a? and its alias Object#kind_of? aren't overrode.
If override? Let's try:
It looks like well. So adding below code to override is_a? and kind_of? before execution.
Finally, run and move with grabbing top level widget successfully. See widget class code is here, and execution code is here.
Why sample widget cannot be moved with grabbing top level widget? It's handled in DragMoveCharm#event_filter method. I had surveyed and debugged this method. Then I found it is caused by incorrect decision of inheritance. See the example code:
> /opt/ruby-1.9.1/bin/irb
irb(main):001:0> require 'Qt'
=> true
irb(main):002:0> Qt::Application.new([])
=> #<Qt::Application:0x00000000c00918 objectName="irb">
irb(main):003:0> label = Qt::Label.new
=> #<Qt::Label:0x00000000befc58 objectName="", x=0, y=0, width=640, height=480>
irb(main):004:0> Qt::Label.ancestors
=> [Qt::Label, Qt::Frame, Qt::Widget, Qt::Object, Qt::PaintDevice, Object, Kernel, BasicObject]
irb(main):005:0> Qt::Label.ancestors.collect do |ancestor_class|
irb(main):006:1* label.is_a? ancestor_class
irb(main):007:1> end
=> [true, false, false, false, false, true, true, true]
After QtRuby 2.0.3, class method Module.ancestors returns not only Ruby's super classes but also Qt's super classes because Qt::Base class overrides this method. But, other related methods don't. Object#is_a? and its alias Object#kind_of? aren't overrode.
If override? Let's try:
> /opt/ruby-1.9.1/bin/irb
irb(main):001:0> require 'Qt'
=> true
irb(main):002:0> module Qt
irb(main):003:1> class Base
irb(main):004:2> def is_a?(mod)
irb(main):005:3> super || self.class.ancestors.include?(mod)
irb(main):006:3> end
irb(main):007:2> end
irb(main):008:1> end
=> nil
irb(main):009:0> Qt::Application.new([])
=> #<Qt::Application:0x00000000ba5c98 objectName="irb">
irb(main):010:0> label = Qt::Label.new
=> #<Qt::Label:0x00000000b94c40 objectName="", x=0, y=0, width=640, height=480>
irb(main):011:0> Qt::Label.ancestors
=> [Qt::Label, Qt::Frame, Qt::Widget, Qt::Object, Qt::PaintDevice, Object, Kernel, BasicObject]
irb(main):012:0> Qt::Label.ancestors.collect do |ancestor_class|
irb(main):013:1* label.is_a? ancestor_class
irb(main):014:1> end
=> [true, true, true, true, true, true, true, true]
It looks like well. So adding below code to override is_a? and kind_of? before execution.
unless Qt::Base.instance_methods(false).include?(:is_a?)
module Qt
class Base
def is_a?(mod)
super || self.class.ancestors.include?(mod)
end
alias :kind_of? :is_a?
end
end
end
Finally, run and move with grabbing top level widget successfully. See widget class code is here, and execution code is here.
Monday, August 17, 2009
drag move charm #1
When we want to move a window on the desktop, we grab the title bar of the window, move it with keeping on grabbing, and release it. Thus we can do it with title bar, but cannot otherwise.
In the graphics-dojo's example "drag move charm", we can move the window not only with grabbing title bar, but also with grabbing top level widget. I learn this example and start to write by QtRuby like below:
and main codes to execute above classes:
Run these codes, 2 charms(widgets) is shown successfully.
But, these can only be moved with grabbing title bar. These yet cannot be moved with grabbing top level widget. to be continued...
In the graphics-dojo's example "drag move charm", we can move the window not only with grabbing title bar, but also with grabbing top level widget. I learn this example and start to write by QtRuby like below:
require 'Qt4'
class DragMoveData
attr_accessor :moving, :start_drag
alias :moving? :moving
end
class DragMoveCharm < Qt::Object
def initialize parent = nil
super
@drag_move_data = {}
end
def activate_on widget
unless @drag_move_data.include?(widget)
data = DragMoveData.new
data.start_drag = Qt::Point.new(0, 0)
data.moving = false
@drag_move_data[widget] = data
widget.install_event_filter(self)
end
end
def deactivate_from widget
@drag_move_data.delete(widget)
widget.remove_event_filter(self)
end
protected
def event_filter(widget, event)
consumed = widget.is_a?(Qt::Widget)
if consumed
type = event.type
case(type)
when Qt::Event::MouseButtonPress,
Qt::Event::MouseButtonRelease,
Qt::Event::MouseMove
consumed = event.kind_of?(Qt::MouseEvent) &&
event.modifiers == Qt::NoModifier &&
@drag_move_data.include?(widget)
if consumed
data = @drag_move_data[widget]
case(type)
when Qt::Event::MouseButtonPress
consumed = event.button == Qt::LeftButton
if consumed
data.start_drag = event.global_pos
data.moving = true
end
when Qt::Event::MouseButtonRelease
data.start_drag = Qt::Point.new(0, 0)
data.moving = false
consumed = false
when Qt::Event::MouseMove
consumed = data.moving?
if consumed
pos = event.global_pos
widget.move(widget.pos + pos - data.start_drag)
data.start_drag = pos;
end
end
end
else
consumed = false
end
end
consumed
end
alias :eventFilter :event_filter
end
and main codes to execute above classes:
require 'dragmovecharm'
require 'qtwebkit'
def image_show
Qt::Label.new do
self.text = "<img src='#{::File.dirname($PROGRAM_NAME)}/pudding.jpg'>"
self.adjust_size
self.window_title = 'Drag to move around'
show
end
end
def mini_browser
Qt::Dialog.new do
self.layout = Qt::VBoxLayout.new do
self.set_contents_margins(3, 15, 3, 3)
end
self.window_flags = Qt::FramelessWindowHint
self.size_grip_enabled = true
self.window_title = 'Drag to move around'
show
tab = Qt::TabWidget.new(self) do
search = Qt::WebView.new(self)
search.load(Qt::Url.new('http://www.google.com/m?hl=en'))
search.set_focus
self.add_tab(search, 'Search')
news = Qt::WebView.new(self)
news.load(Qt::Url.new('http://www.google.com/m/news?source=mobileproducts'))
self.add_tab(news, 'News')
bbc = Qt::WebView.new(self)
bbc.load(Qt::Url.new('http://news.bbc.co.uk/text_only.stm'))
self.add_tab(bbc, 'BBC')
fb = Qt::WebView.new(self)
fb.load(Qt::Url.new('http://iphone.facebook.com'))
self.add_tab(fb, 'Facebook')
end
self.layout.add_widget(tab)
self.resize(350, 500)
(tab.document_mode = true) if Qt::version >= '4.5'
end
end
Qt::Application.new(ARGV) do
charm = DragMoveCharm.new
charm.activate_on(image_show)
charm.activate_on(mini_browser)
exec
end
Run these codes, 2 charms(widgets) is shown successfully.
But, these can only be moved with grabbing title bar. These yet cannot be moved with grabbing top level widget. to be continued...
Monday, August 3, 2009
DigiFlip
I add some sample programs to my graphics-dojo clone repository. 'DigiFlip' sample(the one of added programs this time) is not simple-rewritable one from Qt to QtRuby. There are some points hard to implement. I will now list these.
point 1: Qt::Painter#setBrush
point 2: Qt::Pixmap#fill
point 3: Enum
point 4: Qt::Painter#begin
After implement correctly, let's run it.

'DigiFlip' is here, and others are found from repository top.
point 1: Qt::Painter#setBrush
- It's almost same with phosphorescence: Transparent QtWebView #2, and solution is almost same also. See the entry.
point 2: Qt::Pixmap#fill
- It's similar with above point. A type of Qt::transparent is Qt::GlobalColor, but argument type of Qt::Pixmap#fill is Qt::Color. So Qt::GlobalColor object have to be wrapped with Qt::Color class.
point 3: Enum
- This sample program manages 3 switching mode with enums: Slide, Flip, and Rotate. These are constants and declared as Qt::Enum instance. See also phosphorescence: Qt::Enum.
point 4: Qt::Painter#begin
- If point 1~3 solved, some warning still occur.
QPaintEngine::setSystemRect: Should not be changed while engine is active
This message tells "Forgetting the method call Qt::Painter#begin". So I add this call with checking whether Qt::Painter is active.p = Qt::Painter.new(self)
p.begin(@pixmap) unless p.active?
After implement correctly, let's run it.

'DigiFlip' is here, and others are found from repository top.
Friday, July 31, 2009
Qt::Enum
Most of QtRuby classes have basic classes of Qt. But Qt::Enum is QtRuby original class. Its behavior is almost same with Qt::Integer. And we can use it like as C++ enum.
require 'Qt4'
class Suits < Qt::Object
Heart = Qt::Enum.new(0, self)
Clover = Qt::Enum.new(1, self)
Diamond = Qt::Enum.new(2, self)
Spade = Qt::Enum.new(3, self)
end
Saturday, July 25, 2009
Ruby 1.9.2 preview 1 was released
During RubyKaigi 2009, ruby 1.9.2 preview 1 was also released. So I download and install its package like this entry. Let's check.
Then I re-build Qtruby, but make fails with below messages:
Well, it's often matter of preview release. See the ChangeLog of ruby trunk...
So I fix to use new ruby.h API(refer also some commit comments of the ChangeLog of ruby trunk), send a patch. Currently, it's committed into QtRuby's trunk.
After the revision number 1001987, Building QtRuby with Ruby 1.9.2 succeeds.
>/opt/ruby-1.9.1/bin/ruby --version
ruby 1.9.2dev (2009-07-18 trunk 24186) [x86_64-linux]
Then I re-build Qtruby, but make fails with below messages:
Scanning dependencies of target qtruby4shared
[ 56%] Building CXX object ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/Qt.o
[ 57%] Building CXX object ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/handlers.o
[ 59%] Building CXX object ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/marshall_types.o
/home/youhei/downloads/qt4-qtruby-2.0.3/ruby/qtruby/src/marshall_types.cpp: In function ‘void show_exception_message()’:
/home/youhei/downloads/qt4-qtruby-2.0.3/ruby/qtruby/src/marshall_types.cpp:77: error: ‘STR2CSTR’ was not declared in this scope
make[2]: *** [ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/marshall_types.o] エラー 1
make[1]: *** [ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/all] エラー 2
make: *** [all] エラー 2
Well, it's often matter of preview release. See the ChangeLog of ruby trunk...
Sat Jan 31 22:29:05 2009 Tanaka Akira <akr ! fsij ! org>
* include/ruby/ruby.h (STR2CSTR): removed.
(rb_str2cstr): removed.
* object.c (rb_str2cstr): removed.
So I fix to use new ruby.h API(refer also some commit comments of the ChangeLog of ruby trunk), send a patch. Currently, it's committed into QtRuby's trunk.
After the revision number 1001987, Building QtRuby with Ruby 1.9.2 succeeds.
Wednesday, July 22, 2009
Ruby 1.9.1 p243 was released
During RubyKaigi 2009, ruby 1.9.1 p243 was released. So I download and re-install its package like this entry. Let's check.
Then I re-build Qtruby like this entry.
>/opt/ruby-1.9.1/bin/ruby --version
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]
Then I re-build Qtruby like this entry.
Tuesday, July 7, 2009
Transparent QtWebView #2
(continued from phosphorescence: Transparent QtWebView #1)
This entry had rewritten in 2009/08/03
The biggest reason of this failure is the impedance between Qt that allows overload to Ruby that doesn't allow overload. But in this case, it's 2nd biggest reason: type of Qt class mismatches. A type of Qt::transparent is Qt::GlobalColor, but 2nd argument type of Qt::Palette#setBrush is Qt::Brush. So Qt::GlobalColor object have to be wrapped with Qt::Brush class.
In addition, Qt::Painter#setBrush method is also too. To see the document of QBrush, constructor can take QGradient(superclass of Qt::LinearGradient corrsponding class) and Qt::GlobalColor.
Then I rewrite the previous code like below:
And run it.
Run successfully. I push this code to my gitorious clone repository, see here.
This entry had rewritten in 2009/08/03
The biggest reason of this failure is the impedance between Qt that allows overload to Ruby that doesn't allow overload. But in this case, it's 2nd biggest reason: type of Qt class mismatches. A type of Qt::transparent is Qt::GlobalColor, but 2nd argument type of Qt::Palette#setBrush is Qt::Brush. So Qt::GlobalColor object have to be wrapped with Qt::Brush class.
In addition, Qt::Painter#setBrush method is also too. To see the document of QBrush, constructor can take QGradient(superclass of Qt::LinearGradient corrsponding class) and Qt::GlobalColor.
Then I rewrite the previous code like below:
require 'Qt4'
require 'qtwebkit'
class Container < Qt::Widget
def initialize parent = nil
super
@view = Qt::WebView.new self
pal = @view.palette
pal.set_brush(Qt::Palette::Base, Qt::Brush.new(Qt::transparent))
@view.page.palette = pal
@view.set_attribute(Qt::WA_OpaquePaintEvent, false)
@view.load Qt::Url.new('http://en.mobile.wikipedia.org/')
@view.zoom_factor = 0.8
Qt::Object.connect(@view, SIGNAL( 'titleChanged(const QString&)' ),
self, SLOT( 'setWindowTitle(const QString&)' ))
@layout = Qt::VBoxLayout.new self
@layout.add_widget @view
linear_gradient = Qt::LinearGradient.new
linear_gradient.set_color_at(0.0, Qt::Color.new(249, 247, 96))
linear_gradient.set_color_at(1.0, Qt::Color.new(235, 203, 32))
linear_gradient.coordinate_mode = Qt::Gradient::ObjectBoundingMode
@gradient = Qt::Brush.new(linear_gradient)
self.resize 320, 480
end
protected
def paint_event event
@painter = Qt::Painter.new self
@painter.fill_rect(event.rect, Qt::transparent)
@painter.pen = Qt::NoPen
@painter.brush = @gradient
@painter.opacity = 0.6
@painter.draw_rounded_rect(self.rect, 10, 10)
@painter.end
end
alias :paintEvent :paint_event
end
Qt::Application.new(ARGV) do
Container.new do
self.set_attribute(Qt::WA_TranslucentBackground, true)
self.window_flags = Qt::FramelessWindowHint
show
end
exec
end
And run it.
Run successfully. I push this code to my gitorious clone repository, see here.
Saturday, July 4, 2009
Transparent QtWebView #1
When I read Qt Labs Blogs, I found interesting post titled Transparent QWebView (or QWebPage). As reading this, it's easy that adding a few lines makes background of Webkit transparent, and it can make also by Python (via PyQt).
Then I learn example source codes from Qt's gitorius repository and start to try it by QtRuby. I write sample codes in rubyish like below:
Let's run it!
Oops, undefined method! Really?
Qt::Palette#setBrush exists. Umm... to be continued...
Then I learn example source codes from Qt's gitorius repository and start to try it by QtRuby. I write sample codes in rubyish like below:
require 'Qt4'
require 'qtwebkit'
class Container < Qt::Widget
def initialize parent = nil
super
@view = Qt::WebView.new self
transparent_palette = palette
transparent_palette.setBrush(Qt::Palette::Base, Qt::transparent)
@view.page.palette = transparent_palette
@view.set_attribute(Qt::WA_OpaquePaintEvent, false)
@view.load Qt::Url.new('http://en.mobile.wikipedia.org/')
@view.zoom_factor = 0.8
Qt::Object.connect(@view, SIGNAL( 'titleChanged(const QString&)' ),
self, SLOT( 'setWindowTitle(const QString&)' ))
@layout = Qt::VBoxLayout.new self
@layout.add_widget @view
@gradient = Qt::LinearGradient.new
@gradient.set_color_at(0.0, Qt::Color.new(249, 247, 96))
@gradient.set_color_at(1.0, Qt::Color.new(235, 203, 32))
@gradient.set_coordinate_mode(Qt::Gradient::ObjectBoundingMode)
self.resize 320, 480
end
protected
def paint_event event
@painter = Qt::Painter.new self
@painter.fill_rect(event.rect, Qt::transparent)
@painter.pen = Qt::NoPen
@painter.brush = @gradient
@painter.opacity = 0.6
@painter.draw_rounded_rect(self.rect, 10, 10)
@painter.end
end
alias :paintEvent :paint_event
end
Qt::Application.new(ARGV) do
Container.new do
self.set_attribute(Qt::WA_TranslucentBackground, true)
self.window_flags = Qt::FramelessWindowHint
show
end
exec
end
Let's run it!
> /opt/ruby-1.9.1/bin/ruby transparentweb.rb
transparentweb.rb:10:in `method_missing': undefined method `setBrush' for #<Qt::Palette:0x00000000bd3738> (NoMethodError)
from transparentweb.rb:10:in `initialize'
from transparentweb.rb:45:in `new'
from transparentweb.rb:45:in `block in <main>'
from /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2568:in `instance_eval'
from /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2568:in `run_initializer_block'
from /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:431:in `initialize'
from /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:431:in `initialize'
from transparentweb.rb:44:in `new'
from transparentweb.rb:44:in `<main>'
Oops, undefined method! Really?
> /opt/ruby-1.9.1/bin/rbqtapi -s Qt::Palette | grep setBrush
Qt::Palette#setBrush(Qt::Palette::ColorRole, Qt::Brush)
Qt::Palette#setBrush(Qt::Palette::ColorGroup, Qt::Palette::ColorRole, Qt::Brush)
Qt::Palette#setBrush exists. Umm... to be continued...
Thursday, July 2, 2009
QtWebkit over the proxy
I wrote some posts about QtWebkit. But these may fail if your program runs behind the proxy. Then I rewrite programs in phosphorescence: QtWebkit HTML5 practice like below. Additional codes are blue characters.
Qt program
QtRuby program
proxy.host and proxy.port should replace ones of your proxy environment.
Qt program
#include <QApplication>
#include <QUrl>
#include <QWebView>
#include <QNetworkProxy>
int main(int argc, char *argv[]){
QApplication a(argc, argv);
QNetworkProxy proxy(QNetworkProxy::HttpProxy, "proxy.host", proxy.port);
QNetworkProxy::setApplicationProxy(proxy);
QUrl url("http://htmlfive.appspot.com/static/draw.html");
QWebView* webView = new QWebView();
webView->load(url);
webView->show();
return a.exec();
}
QtRuby program
require 'Qt4'
require 'qtwebkit'
Qt::Application.new(ARGV) do
proxy = Qt::NetworkProxy.new(Qt::NetworkProxy::HttpProxy, "proxy.host", proxy.port)
Qt::NetworkProxy.application_proxy = proxy
Qt::WebView.new do
self.load Qt::Url.new('http://htmlfive.appspot.com/static/gifter.html')
show
end
exec
end
proxy.host and proxy.port should replace ones of your proxy environment.
Subscribe to:
Posts (Atom)


