Results 1 to 20 of 20

Thread: White background in window, getting desperate!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: White background in window, getting desperate!

    Quote Originally Posted by fatjuicymole View Post
    This is correct behavior on Windows, nothing will be drawn until the window gets a draw event, which can't occur until the sleep function has completed and the event loop continued. Qt will not attempt any drawing event (which includes the window background) until it gets such an event.
    Indeed. So this (some kind of Erase Background event being fired & processed) is not the reason for my window to have a white background beneath its real content. Which is the problem I'm trying to solve.

    Any idea?

    Cheers,
    Franz

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: White background in window, getting desperate!

    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.

  3. #3
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: White background in window, getting desperate!

    Quote Originally Posted by fatjuicymole View Post
    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.
    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?

    Quote Originally Posted by fatjuicymole View Post
    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?
    Hm, I'd rather avoid having to do that But it could be interesting, as an experiment to figure out what is really happening.

    Quote Originally Posted by fatjuicymole View Post
    Other than that, I've no idea. It's not something I've come across in Qt, as all my Window backgrounds are white.
    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

  4. #4
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: White background in window, getting desperate! (now with demonstration program)

    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:
    1. void MainWindow::hide_show()
    2. {
    3. hide();
    4. show();
    5. }
    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:
    1. void MainWindow::hide_show_slow()
    2. {
    3. hide();
    4. Sleep(1000);
    5.  
    6. show();
    7. 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.
    8. }
    To copy to clipboard, switch view to plain text mode 

    The application is styled using this stylesheet:

    Qt Code:
    1. {
    2. background-color: rgb(50, 50, 50);
    3. }
    4.  
    5. {
    6. background-color: rgb(150, 150, 150);
    7. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    Franz
    Last edited by dictoon; 30th December 2009 at 12:55.

  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: White background in window, getting desperate!

    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):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. #6
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: White background in window, getting desperate!

    Quote Originally Posted by faldżip View Post
    can you share the source code of this example?
    Sure, here we go.

    Quote Originally Posted by faldżip View Post
    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.
    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

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: White background in window, getting desperate! (now with demonstration program)

    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:
    1. void MainWindow::mySleep( int ms )
    2. {
    3. QEventLoop loop;
    4.  
    5. QTimer::singleShot(ms,&loop,SLOT(quit()));
    6. loop.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: White background in window, getting desperate! (now with demonstration program)

    Quote Originally Posted by Lesiok View Post
    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:
    1. void MainWindow::mySleep( int ms )
    2. {
    3. QEventLoop loop;
    4.  
    5. QTimer::singleShot(ms,&loop,SLOT(quit()));
    6. loop.exec();
    7. }
    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

  9. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: White background in window, getting desperate!

    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]

  10. #10
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: White background in window, getting desperate!

    Quote Originally Posted by fatjuicymole View Post
    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

  11. #11
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: White background in window, getting desperate! (now with demonstration program)

    Quote Originally Posted by dictoon View Post
    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
    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.

  12. #12
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: White background in window, getting desperate! (now with demonstration program)

    Quote Originally Posted by Lesiok View Post
    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

  13. #13
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: White background in window, getting desperate! (now with demonstration program)

    Quote Originally Posted by dictoon View Post
    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....
    I know this. Therefore I wrote in my last clause And in Yours real application You must blocking event loop with some long process (called after showing window).

  14. #14
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: White background in window, getting desperate! (now with demonstration program)

    Quote Originally Posted by Lesiok View Post
    I know this. Therefore I wrote in my last clause And in Yours real application You must blocking event loop with some long process (called after showing window).
    Of course in my real app I don't have any sleep(), nor do I have any long process running I 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

Similar Threads

  1. How to set Qt window transparent?
    By montylee in forum Qt Programming
    Replies: 17
    Last Post: 24th December 2013, 20:11
  2. Replies: 2
    Last Post: 9th August 2009, 22:08
  3. Window Background
    By QbelcorT in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 23rd September 2008, 06:03
  4. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 15:40
  5. Replies: 15
    Last Post: 23rd March 2007, 16:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.