[Qt-interest] Making part of QWebView as transaparent

Samuel Rødal sroedal at trolltech.com
Wed Dec 16 09:50:38 CET 2009


Nitin Mahajan wrote:
> HI,
> 
> --- On Tue, 15/12/09, Samuel Rødal <sroedal at trolltech.com> wrote:
> 
>> From: Samuel Rødal <sroedal at trolltech.com>
>> Subject: Re: [Qt-interest] Making part of QWebView as transaparent
>> To: nitinm76 at yahoo.com
>> Cc: qt-interest at trolltech.com
>> Date: Tuesday, 15 December, 2009, 6:23 PM
>> Nitin Mahajan wrote:
>>> Hello,
>>>
>>> I am trying to make a part of QWebView as transparent
>> using setMask(). I am doing this experiment with the demo
>> browser.
>>> The demo browser is allowed to run for some time.Later
>> some region of web view is made transparent using setMask().
>>
>>> What I find is that the region where a whole should
>> have been punched remains white, instead of becoming
>> transparent. Can some one help me with this?
>>> regards
>>>
>>> -Nitin
>> Are you sure you're using setMask() on a top-level widget?
>> Otherwise there won't be any transparency as there'll be
>> another widget behind.
>>
> 
> You are right. I forgot to set mask on BrowserMainWindow. After doing that the transparency is fine. 
> 
> Now I have a new problem. The Area where I punch a hole in webview,had a child widget. That widget is also not being shown now. I want to show that child widget with some transparency.
> 
> Can I get, some pointers towards this?
> 
> regards
> 
> -Nitin

With setMask() you can only get either fully opaque or fully transparent 
pixels. If you want semi transparency you need to not use setMask() but 
use the window attribute Qt::WA_TranslucentBackground on the top level.

You then need to override the top level's paint event to source fill the 
areas where you want transparency with Qt::transparent, something like this:

// first let the parent do its drawing
ParentClass::paintEvent(event);

QPainter p(this);
p.setCompositionMode(QPainter::CompositionMode_Source);

// fill the region where you want transparency
foreach (QRect rect, transparentRegion);
     p.fillRect(rect, Qt::transparent);

--
Samuel



More information about the Qt-interest-old mailing list