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:

require 'Qt4'
require 'qtwebkit'

class Container < Qt::Widget

  def initialize parent = nil

    @view = self
    transparent_palette = palette
    transparent_palette.setBrush(Qt::Palette::Base, Qt::transparent) = transparent_palette
    @view.set_attribute(Qt::WA_OpaquePaintEvent, false)
    @view.zoom_factor = 0.8

    Qt::Object.connect(@view, SIGNAL( 'titleChanged(const QString&)' ),
      self, SLOT( 'setWindowTitle(const QString&)' ))

    @layout = self
    @layout.add_widget @view

    @gradient =
    @gradient.set_color_at(0.0,, 247, 96))
    @gradient.set_color_at(1.0,, 203, 32))

    self.resize 320, 480

  def paint_event event
    @painter = 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)

  alias :paintEvent :paint_event
end do do
    self.set_attribute(Qt::WA_TranslucentBackground, true)
    self.window_flags = Qt::FramelessWindowHint

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...

No comments:

Post a Comment