Results 1 to 7 of 7

Thread: WindowStaysOnTopHint

  1. #1
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default WindowStaysOnTopHint

    Hello! I want to implement a simple function to toggle normal window/on top state. For this, I write this code:
    Qt Code:
    1. Qt::WindowFlags f = 0;
    2.  
    3. Qt::WindowFlags flags = windowFlags ();
    4. if (flags & Qt::WindowStaysOnTopHint)
    5. f = Qt::Window;
    6. else
    7. {
    8. f = Qt::Window;
    9. f |= Qt::WindowStaysOnTopHint;
    10. }
    11. setWindowFlags (f);
    To copy to clipboard, switch view to plain text mode 
    But when I run it, the window just disappears.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: WindowStaysOnTopHint

    If you want to toggle one flag use this code:
    Qt Code:
    1. Qt::WindowFlags flags = windowFlags();
    2. flags ^= Qt::WindowStaysOnTopHint;
    3. setWindowFlags( flags );
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to jacek for this useful post:

    roxton (18th August 2008)

  4. #3
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: WindowStaysOnTopHint

    But the window disappears anyway!
    I'm trying to apply this "toggle" to the main window.
    P.S.: Qt 4.4, Linux

  5. #4
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: WindowStaysOnTopHint

    Update:
    This code works fine ,and the window is visible:
    Qt Code:
    1. Qt::WindowFlags flags = windowFlags();
    2. flags ^= Qt::WindowStaysOnTopHint;
    3. setWindowFlags( flags );
    4. show();
    5. activateWindow();
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Oct 2006
    Location
    Massachusetts, USA
    Posts
    19
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: WindowStaysOnTopHint

    The documentation for setWindowFlags() states that it calls setParent(), which in turn documents that it hides the window, necessitating the call to show(). But it appears you discovered that.

    I have another question related to WindowStaysOnTopHint. I notice that when I toggle the option on my top level widget (by means of a checkbox in the window itself), the widget is automatically repositioned on the screen. It's harmless but annoying. Is there a simple way to suppress that repositioning action?

  7. #6
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: WindowStaysOnTopHint

    Quote Originally Posted by McKee View Post
    The documentation for setWindowFlags() states that it calls setParent(), which in turn documents that it hides the window, necessitating the call to show(). But it appears you discovered that.

    I have another question related to WindowStaysOnTopHint. I notice that when I toggle the option on my top level widget (by means of a checkbox in the window itself), the widget is automatically repositioned on the screen. It's harmless but annoying. Is there a simple way to suppress that repositioning action?
    I don't know, but my guess is maybe by reimplementing the paint function (paintEvent()?) and set a position you want it to be drawn an then call its parents paint function

  8. #7
    Join Date
    Jun 2008
    Posts
    89
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: WindowStaysOnTopHint

    But using
    Qt Code:
    1. Qt::WindowFlags flags = windowFlags();
    2. flags ^= Qt::WindowStaysOnTopHint;
    3. setWindowFlags( flags );
    4. show();
    5. activateWindow();
    To copy to clipboard, switch view to plain text mode 

    the window remains on the top of all running applications. what if we just want it to be bound with my application and not other applications running.

    When i press ALT + Tab the window whose flag was set remains on top of new application..this is not what is expected..

    What can be done to avoid this behavior and retaining WindowStaysOnTopHint?

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.