Results 1 to 10 of 10

Thread: How to make a window stay on top of all others?

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How to make a window stay on top of all others?

    Hello!

    The software I'm currently developing needs to, from time to time, show its MainWindow form in a way that it stays on top over all other running applications in Windows, but I couldn't find how to do this.

    I heard that "this->raise()" only works with windows of the application itself, and "Qt::WindowStaysOnTopHint" works for QWidget, but not QMainWindow.

    Interesting to notice that I'm using showFullScreen() for the MainWindow, but that don't do what I want exactly: it covers the area (including the taskbar) correctly, but if a software is opened, it appears over the MainWindow form, and that's what I don want.

    If the analogy is usefull, what I want is exactly equal to the Borland C++ Builder function:

    Qt Code:
    1. Form->FormStyle = fsStayOnTop;
    To copy to clipboard, switch view to plain text mode 

    What happens with this code is that the window stay on top doesn't matter which other window you work with or other software you open.



    Thanks!

    Momergil

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make a window stay on top of all others?

    some extra points here http://www.qtforum.org/article/23135...iosk-mode.html . Does it help?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to make a window stay on top of all others?

    Quote Originally Posted by amleto View Post
    some extra points here http://www.qtforum.org/article/23135...iosk-mode.html . Does it help?
    Hello!

    Thanks amleto, but it doesn't help. The slot I already use, as I sad, but it must stay always on top over all other softwares in the desktop.

    Qt::FramelessWindowHint has nothing to do with what I want, and given the fact I'm using the slot to show in full screen, I see no use for Qt::WindowFullScreen.



    Obs.: Correction: Qt::WindowStaysOnTopHint does work for QMainWindow; I was just using the incorrect function. It works with "this->setWindowFlags(Qt::WindowStaysOnBottomHint);", but unfortunately it still don't do what I need.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to make a window stay on top of all others?

    Obs.: Correction: Qt::WindowStaysOnTopHint does work for QMainWindow; I was just using the incorrect function. It works with "this->setWindowFlags(Qt::WindowStaysOnBottomHint);", but unfortunately it still don't do what I need.
    So it works but it doesn't work? Which is it?

  5. #5
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to make a window stay on top of all others?

    Quote Originally Posted by ChrisW67 View Post
    So it works but it doesn't work? Which is it?
    ^^

    First I thought it didn't work because I tried to implement it with the wrong funtion ("setAttribute()"), but later I discovered that the correct function was "setWindowFlags()". Nevertheless, it don't do what I need (to make the form stay on top over all other windows/softwares).

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

    Default Re: How to make a window stay on top of all others?

    Quote Originally Posted by Momergil View Post
    Nevertheless, it don't do what I need (to make the form stay on top over all other windows/softwares).
    So what does it do if it doesn't make your window stay on top of other windows?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to make a window stay on top of all others?

    Quote Originally Posted by wysota View Post
    So what does it do if it doesn't make your window stay on top of other windows?
    As far as I understood, by the way the Google Talk plugin that warns the user when new messsage has arrived while the GMail webpage is not focused and by the documentation, this hint put the current window of the application to stay on top over the other windows of the SAME application, but not over the desktop. By the other hand, it seems that it somehow tells Windows that the software is over the desktop, because while my test software with the hint was on, the Google Talk plugin was warning even when the focus was over the GMail webpage.

    So, it's quite confusing exactly what he does or else tells Windows what it should do, but nevertheless it still don't do what I need.

    Once again what I need:

    This form remains on top of the desktop and of other forms in the project

    [except any others that also have FormStyle set to fsStayOnTop.If one fsStayOnTop form launches another, neither form will consistently remain on top.]

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

    Default Re: How to make a window stay on top of all others?

    Quote Originally Posted by Momergil View Post
    As far as I understood, by the way the Google Talk plugin that warns the user when new messsage has arrived while the GMail webpage is not focused and by the documentation, this hint put the current window of the application to stay on top over the other windows of the SAME application, but not over the desktop.
    I don't know what Google Talk has to do with this, but no, the hint makes a window stay on top of other windows regardless of which application they belong to.

    I don't see how you intend to solve any of your problems if you're not even trying solutions you are given but instead trust what you think the solution does. Trying the hint would take you about two minutes which is definitely less than you writing your last post and me reading and answering it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to make a window stay on top of all others?

    Quote Originally Posted by wysota View Post
    I don't see how you intend to solve any of your problems if you're not even trying solutions you are given but instead trust what you think the solution does.
    When did I say that I wasn't trying? I even sad:

    (...) because I tried to implement it with the wrong funtion (...)
    in post 5, and in post 7 I described the results of my tests!

    ---
    the hint makes a window stay on top of other windows regardless of which application they belong to.
    Actually you're right, it does; the problem is that the help file wasn't clear enough (for me) regarding how to USE the hint; I was trying wrongly

    Qt Code:
    1. setWindowFlags(Qt::WindowStaysOnTopHint);
    To copy to clipboard, switch view to plain text mode 

    when actually it should be

    Qt Code:
    1. setWindowFlags(Qt::Window | Qt::WindowStaysOnTopHint);
    To copy to clipboard, switch view to plain text mode 

    as the help files says:

    Window flags are a combination of a type (e.g. Qt:ialog) and zero or more hints to the window system (e.g. Qt::FramelessWindowHint).
    Unfortunately the lack of e.g.: "in using this function, you should first enter the type of the form you're using (e.g. QDialog, QWindow, etc.) and combined with it the hint you want to use it, if applicable (e.g. Qt::WindowStaysOnTopHint)" was the problem I got.




    Anyway, thanks for the help. Unfortunately, though, there is still the problem that the hint isn't able to cover 100% the taskbar; when another software is started during the usage of the hint, the taskbar turns visible to show the flashing icon of the new opened software.


    Momergil

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

    Default Re: How to make a window stay on top of all others?

    Quote Originally Posted by Momergil View Post
    When did I say that I wasn't trying?
    I said that.

    the problem is that the help file wasn't clear enough (for me) regarding how to USE the hint
    Or maybe you just didn't read it carefully enough. The first sentence of documentation says: "Window flags are a combination of a type (e.g. Qt::Dialog) and zero or more hints to the window system". What follows is a link to "Windows Flags example" which you could have just run and test what each flag does.

    Unfortunately the lack of e.g.: "in using this function, you should first enter the type of the form you're using (e.g. QDialog, QWindow, etc.) and combined with it the hint you want to use it, if applicable (e.g. Qt::WindowStaysOnTopHint)" was the problem I got.
    It says "combination". To me the term is clear. It doesn't matter if you use Qt::Window|Qt::WindowStaysOnTopHint or Qt::WindowStaysOnTopHint|Qt::Window or even QWidget::windowFlags()|Qt::WindowStaysOnTopHint.

    Anyway, thanks for the help. Unfortunately, though, there is still the problem that the hint isn't able to cover 100% the taskbar;
    The taskbar is not the client area of the screen, you will not be able to put a non-fullscreen window over it if the desktop manager doesn't let you to.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Make frameless tool window stay on top of the application
    By ainne810329 in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2012, 11:37
  2. Replies: 1
    Last Post: 19th January 2010, 22:05
  3. Replies: 2
    Last Post: 10th December 2009, 07:01
  4. Replies: 4
    Last Post: 4th June 2007, 12:07
  5. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43

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