Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Make some windows always show up in front of a certain window
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.5k Views 2 Watching
  • 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 Offline
    D Offline
    Donald Duck
    wrote on last edited by
    #1

    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
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by mostefa
      #2

      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
      1
      • M 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 Offline
        D Offline
        Donald Duck
        wrote on last edited by
        #3

        @mostefa Thanks, it worked.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved