PDA

View Full Version : WindowStaysOnTopHint



roxton
18th August 2008, 11:03
Hello! I want to implement a simple function to toggle normal window/on top state. For this, I write this code:


Qt::WindowFlags f = 0;

Qt::WindowFlags flags = windowFlags ();
if (flags & Qt::WindowStaysOnTopHint)
f = Qt::Window;
else
{
f = Qt::Window;
f |= Qt::WindowStaysOnTopHint;
}
setWindowFlags (f);

But when I run it, the window just disappears.

jacek
18th August 2008, 15:09
If you want to toggle one flag use this code:

Qt::WindowFlags flags = windowFlags();
flags ^= Qt::WindowStaysOnTopHint;
setWindowFlags( flags );

roxton
18th August 2008, 16:05
But the window disappears anyway!
I'm trying to apply this "toggle" to the main window.
P.S.: Qt 4.4, Linux

roxton
18th August 2008, 18:39
Update:
This code works fine ,and the window is visible:


Qt::WindowFlags flags = windowFlags();
flags ^= Qt::WindowStaysOnTopHint;
setWindowFlags( flags );
show();
activateWindow();

McKee
24th August 2008, 03:31
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?

Boy
26th August 2008, 13:21
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

kaushal_gaurav
28th August 2008, 05:22
But using


Qt::WindowFlags flags = windowFlags();
flags ^= Qt::WindowStaysOnTopHint;
setWindowFlags( flags );
show();
activateWindow();


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?