Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    3
    828
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      Donald Duck last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • M
        mostefa last edited by mostefa

        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
        .
        .
        .
        
        }
        
        D 1 Reply Last reply Reply Quote 1
        • D
          Donald Duck @mostefa last edited by

          @mostefa Thanks, it worked.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post