If you double buffered the window (Not sure how you do this in Qt, as I've only done it in MFC), then Windows keeps an entire copy of your window in memory. Therefore when the window is shown, it will have the old contents until it's redrawn rather than being white.
Or, perhaps a hack/trick: you could resize the window to 1x1, show the window, let Qt kick it's redraw event, then resize it again and maybe it'll be invalidated and resized in the same paint event?
Other than that, I've no idea. It's not something I've come across in Qt, as all my Window backgrounds are white.
As far as I know, in recent versions of Qt (I'm using Qt 4.5.2), all windows are double-buffered. Or are you talking about another form of double buffering?
Hm, I'd rather avoid having to do thatBut it could be interesting, as an experiment to figure out what is really happening.
Well, thanks for your input so far.
I'm definitely looking for a solution for this problem. It basically surfaces every time a window is supposed to have a non-white background: for some reason there is still a white background being rendered underneath the real window contents, and it gets visible in some situations.
I believe I need to demonstrate the effect with a small sample and post the binary here, in order to show how bad it can occasionally get.
In any case: Qt experts, please shed some light on this issue
Cheers,
Franz
Here is a Win32 executable that demonstrates the problem. The file is somewhat large (5 MB) because I included all the required DLL.
Clicking the button "Hide And Show This Window At Normal Speed" executes this code:
Qt Code:
void MainWindow::hide_show() { hide(); show(); }To copy to clipboard, switch view to plain text mode
Clicking the button "Hide And Show This Window In Slow Motion" executes this one:
Qt Code:
void MainWindow::hide_show_slow() { hide(); Sleep(1000); show(); Sleep(1000); // Here you'll have one second to see the white background of the window, before the paint event kicks in and display the gray background on top of it. }To copy to clipboard, switch view to plain text mode
The application is styled using this stylesheet:
Qt Code:
{ background-color: rgb(50, 50, 50); } { background-color: rgb(150, 150, 150); }To copy to clipboard, switch view to plain text mode
Cheers,
Franz
Last edited by dictoon; 30th December 2009 at 12:55.
can you share the source code of this example?
I ran it on my Windows7 x64 and there is no white background even with slow motion button.
Later I'll try it on WinXP.
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Sure, here we go.
That's very interesting, thanks. I'd be curious to know if maybe the problem is specific to Vista x64, or even to my machine (Dell Latitude E6500 with some Intel GPU).
Cheers,
Franz
Calling Sleep() You are blocking a thread and event loop. Window is repainted in more when one event. Just replace Sleep() with mySleep like this :
Qt Code:
void MainWindow::mySleep( int ms ) { QEventLoop loop; loop.exec(); }To copy to clipboard, switch view to plain text mode
Hi, thanks for your answer. However, please read the thread from the beginning. I'm blocking the thread (and the event loop) on purpose, in order to demonstrate a problem (bug?) that I have hit with Qt.
By the way, just to gather some more stats: have you tried the application demonstrating the problem? If so, do you see the window's background being filled to white before the window's content gets rendered? What's your operating system?
Cheers,
Franz
I don't get it white. I get the window drawn with no background (or a completely transparent background, depending on how you want to describe it) until the event loop draws the window.
I really don't think this is a Qt problem, but more like how the OS handles Windows.
[This is under WinXP 32-bit]
Interesting, thanks for the input.
So, it does seem to be platform-specific and even Windows-version specific. I'd be interested to know if it's Vista x64 only. I doubt that it is worth spending more time on this issue if the problem is limited to this platform.
Cheers,
Franz
Yes, I have tried this demo and have this same behaviour as fatjuicymole. After changing sleep method all is working perfect.
On Windows VISTA with AERO background is white, without AERO window have no background. This is a problem with Windows not with Qt.
And in Yours real application You must blocking event loop with some long process.
About the sleep method: again, I inserted calls to Sleep() in order to block the current thread and prevent messages from being processed, *intentionally*. This is just a test app to demonstrate the problem, and make it obvious.
About Aero: that's very interesting, I didn't think of trying with Aero disabled. So this seems to confirm that it's a Windows bug, and that's it's specific to Vista+Aero. Would love to find a workaround on this platform. Good to know that the problem does not seem to be reproducible on Windows 7.
Thanks for your input.
Cheers,
Franz
Of course in my real app I don't have any sleep(), nor do I have any long process runningI just have a very basic window, with half a dozen very basic controls. It's just that this window (like all windows of my application) has a dark gray background, and when I bring it to the screen -- by calling show() on it -- there's a very noticeable, very disturbing white flash due to the fact that the window first appears with a completely white background, leaving a small delay until the real window contents gets rendered.
Cheers,
Franz
Bookmarks