Qt toggle always on top for a QMainWindow
        Posted  
        
            by Jake Petroules
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jake Petroules
        
        
        
        Published on 2010-05-18T09:30:22Z
        Indexed on 
            2010/05/22
            20:20 UTC
        
        
        Read the original article
        Hit count: 279
        
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 reshown 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?
© Stack Overflow or respective owner