PDA

View Full Version : $20 to solve this webview transparency / drawing bug



TheNewGuy
15th March 2010, 21:38
Source code found in Files.tar.gz

Okay, I do not have much experience with C++ or QT. This issue has been kicking my ass for a long time, so I will give $20 via paypal to the first person who can solve it for me once in for all. I know its not much, but hopefully you will like the challenge. The attached code is largely complete. There are just small issues I am sure someone with more experience would know about right away.

What I am trying to do:

When someone left clicks in a widget then a popup box is shown to the user at the click location. The popup box may vary in size, shape (not always rectangle... Sometimes it is multiple connecting rectangles). The box (a qt webview widget) needs to disappear if anywhere on the screen is clicked much the same way that a context menu does. The size of the widget which contains the popup box must span the space of the screen and have a transparent background.

The Problem

Windows

On windows, it largely works. The issue with windows is a flicker. Click once and it popups up as expected. Click again in a different area and for a split second you can see it in the previous area. There is no reason for it to do this. It is almost as if QT shows a cached version of what the menu used to look like before drawing the new version.

http://imgur.com/FiGmj.jpg

Linux

On linux, it is just a mess. The transparency does not work, so when the popup comes up it completely messes up what is in the background (it does not show a black background instead of transparent.... It shows whatever is behind the widget as it should, but then breaks it apart and randomizes all the pieces). And, probably a sympton of the same issue, the widget never redraws itself so just keeps on adding popup box after popup box. The only way to show the effect is with a picture. In the picture you will see blue boxes. That is the popup. The other stuff are just windows opened behind the application. As you can see, it completely messed up the desktop while it was open.

http://imgur.com/5zQWv.jpg

The source code is in Files.tar.gz

norobro
16th March 2010, 04:21
If I use my imagination I can see the desktop through the black. What distro are you running? I run Debian Sid, KDE 4.3.4 & Qt 4.6.0.

TheNewGuy
16th March 2010, 04:25
I run Ubuntu 9.10 with QT 4.6.2.

I am not 100% positive on this, but I imagine you are getting a black background because you do not have compositing enabled. I have read that compositing must be enabled for transparency support in linux desktops.

norobro
16th March 2010, 17:01
Yeah, I have compositing enabled. I've had problems with transparency before. I have an older machine with a wimpy graphics card that doesn't have the horsepower to handle all of the desktop effects.

Transparency issues aside, unless I misunderstand, I get the behavior that you describe for windows.

Attached is a Gnome screenshot.

TheNewGuy
16th March 2010, 18:41
Yeah, the issue is only there if transparency is working. I have set the HTML document (menu.html) to have a black background before and the issue largely resolves itself. However, with transparency things go haywire. I am beginning to think that it is just a bug in QT. I have tried it on multiple systems with different graphic cards and the result is the same. I do not think it can be graphic card related because both systems I have tested it on are able to run compizfusion with every effect on. Since I do not understand how QT draws and everything I was hoping there was something fancy to do with paint events or something to get it to work or to at least stop the flickering on windows.

norobro
16th March 2010, 19:31
Sorry, I guess that I can't help since I ain't got no stinkin' transparency.

Have you tried your app on a system running KDE?

wysota
16th March 2010, 23:17
Do you open your popup as a real popup (i.e. with proper window flags)? The answer is probably in your code but I don't have time to look into it right now :)

TheNewGuy
16th March 2010, 23:30
The menu popup is created in the following way. Keep in mind I am new to QT and C++. I am sure it is not very pretty. I have literally tried a 100 different combinations of flags. This is just the latest (and the one in the test case). There is a good chance it is my code. I am probably doing something really dumb and obvious to anyone else.



LHMenu::LHMenu()
: LHWebView(), caller(0)
{
setWindowModality(Qt::ApplicationModal);

QPalette qpalette = palette();
qpalette.setBrush(QPalette::Base, Qt::transparent);
page()->setPalette(qpalette);

setAttribute(Qt::WA_OpaquePaintEvent, false);
setAttribute(Qt::WA_TranslucentBackground, true);

setWindowFlags(Qt::FramelessWindowHint | Qt::SplashScreen);

page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);

setContextMenuPolicy(Qt::NoContextMenu);

connect(page(), SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));

load(QUrl("qrc:/menu.html"));
}

wysota
16th March 2010, 23:35
That's not good. Try:

setWindowFlags(Qt::Popup);
or

setWindowFlags(Qt::ToolTip);

Also try simplifying your code as much as possible. First of all see how everything behaves when you substitute QWebView with some other widget (say... QLabel).