PDA

View Full Version : How to make a window stay on top of all others?



Momergil
10th July 2012, 18:51
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:


Form->FormStyle = fsStayOnTop;

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

amleto
10th July 2012, 19:41
some extra points here http://www.qtforum.org/article/23135/going-full-screen-kiosk-mode.html . Does it help?

Momergil
10th July 2012, 22:38
some extra points here http://www.qtforum.org/article/23135/going-full-screen-kiosk-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.

ChrisW67
11th July 2012, 01:45
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?

Momergil
11th July 2012, 20:48
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).

wysota
12th July 2012, 10:13
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?

Momergil
12th July 2012, 22:01
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.]

wysota
12th July 2012, 22:23
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.

Momergil
16th July 2012, 20:46
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


setWindowFlags(Qt::WindowStaysOnTopHint);

when actually it should be


setWindowFlags(Qt::Window | Qt::WindowStaysOnTopHint);

as the help files says:


Window flags are a combination of a type (e.g. Qt::Dialog) 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

wysota
16th July 2012, 21:25
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.