Make some windows always show up in front of a certain window



  • I have a main window and a few other windows and I would like to do so that the main window is always behind the other windows. First I tried to use setWindowFlags(Qt::WindowStaysOnBottomHint) on the main window and that had no effect. So then I tried to do so that the window automatically goes on the bottom when it gets focused on by adding this to the class from which the main window is created:

    void MainWindow::focusInEvent(QFocusEvent*){
        lower();
    }
    

    This still had no effect. Then I saw here that for lower() to work, apparently the main window and the other windows need to have the same parent widget. So I created a widget which is supposed to be the parent widget of all other widgets and used setParent(parentWidget) on the main window and all the other windows. But the problem with that is that then the main window couldn't be opened and whenever it is the only window in the program that's supposed to be opened the program exits with code 0.

    The only solution that does something acceptable is to use setWindowFlags(Qt::WindowStaysOnTopHint) on all windows except the main window. But the problem is that then those windows will stay on top of any window, even those that are part of other programs, which I don't want.

    How can I solve this issue?



  • Hi @Donald-Duck

    If you want that your mainWindow will stay always on the bottom of other windows , i think that your widgets need to have mainWindow as parent
    In your MainWindow.cpp

    
    {
    .
    .
    .
    
                yourWidget = new QWidget(this);//  *this* means that parent of your widget is mainWindow
    .
    .
    .
    
    }
    


  • @mostefa Thanks, it worked.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.