Results 1 to 6 of 6

Thread: Changing AlwaysOnTop window flag

  1. #1
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Changing AlwaysOnTop window flag

    Hey guys. I have this app that the user can choose if he/she wants it always on top or not via a menu option. This is a chackable menu action that toggles the following method:

    Qt Code:
    1. void MainForm::menuAlwaysOnTop(bool bEnable)
    2. {
    3. if (bEnable == true)
    4. {
    5. // This line is hiding my window :(
    6. setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
    7. }
    8. else
    9. {
    10. // remove Qt::WindowStaysOnTopHint
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    My MainForm class derives from QMainWindow. The problem I am having is that when this method runs... my window disappears! Augh. I can't explain why. Does anyone have an idea of what I can do to fix this?

  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: Changing AlwaysOnTop window flag

    Does it disappear when bEnable is true or when it's false?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Changing AlwaysOnTop window flag

    Did you try calling show() on the widget again?

  4. #4
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Changing AlwaysOnTop window flag

    It happens when bEnable == true. ... calling show() right afterwords did the trick. Is this by design? It seems a little funny.

  5. #5
    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: Changing AlwaysOnTop window flag

    Quote Originally Posted by bpetty View Post
    It seems a little funny.
    Indeed, it's weird, but it musn't be necessarily Qt's fault.

  6. #6
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Changing AlwaysOnTop window flag

    For all of those interested in a working code snippet 4 your own projects:

    Qt Code:
    1. ui.actionAlwaysOnTop->setCheckable(true);
    2. connect(ui.actionAlwaysOnTop, SIGNAL(toggled(bool)), this, SLOT(menuAlwaysOnTop(bool)));
    3.  
    4. ...
    5.  
    6. void MainForm::menuAlwaysOnTop(bool bEnable)
    7. {
    8. if (bEnable == true)
    9. {
    10. setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
    11. }
    12. else
    13. {
    14. setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
    15. }
    16.  
    17. show();
    18. }
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to bpetty for this useful post:

    No-Nonsense (20th February 2007)

Similar Threads

  1. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  2. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21
  3. Replies: 5
    Last Post: 13th March 2006, 20:22

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.