void MainWindow::on_actionAlways_on_Top_triggered(bool checked)
{
Qt::WindowFlags flags = this->windowFlags();
if (checked)
{
this->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
this->show();
}
else
{
this->setWindowFlags(flags ^ (Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint));
this->show();
}
}
The above solution works but because setWindowFlags hides the window, it needs to be re-shown and of course that doesn’t look very elegant. So how do I toggle “always on top” for a QMainWindow without that “flashing” side effect?
Nokia says no:
But sometimes if you’re stuck with a flashing effect that’s kind of ugly like this, you can intentionally drag it out to make it seem like something “cool” just happened.
Maybe pop up a little progress bar that’s not in the window, say “Adjusting Window Properties!”…fade the window out of existence and then back in, and close the progress bar popup.