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:
Code:
void MainForm::menuAlwaysOnTop(bool bEnable)
{
if (bEnable == true)
{
// This line is hiding my window :(
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
}
else
{
// remove Qt::WindowStaysOnTopHint
}
}
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?
Re: Changing AlwaysOnTop window flag
Does it disappear when bEnable is true or when it's false?
Re: Changing AlwaysOnTop window flag
Did you try calling show() on the widget again?
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.
Re: Changing AlwaysOnTop window flag
Quote:
Originally Posted by
bpetty
It seems a little funny.
Indeed, it's weird, but it musn't be necessarily Qt's fault.
Re: Changing AlwaysOnTop window flag
For all of those interested in a working code snippet 4 your own projects:
Code:
ui.actionAlwaysOnTop->setCheckable(true);
connect(ui.actionAlwaysOnTop, SIGNAL(toggled(bool)), this, SLOT(menuAlwaysOnTop(bool)));
...
void MainForm::menuAlwaysOnTop(bool bEnable)
{
if (bEnable == true)
{
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
}
else
{
setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
}
show();
}