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. Keep windows on top within application
Forum Updated to NodeBB v4.3 + New Features

Keep windows on top within application

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.5k Views 1 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.
  • P Offline
    P Offline
    patrcki
    wrote on last edited by
    #1

    Hi there,

    I'm trying to set up my app to keep certain main windows above other main windows, when any of my app's windows have focus. I believe this behavior I'm trying to get is similar to WS_EX_PALETTEWINDOW (or WS_EX_TOPMOST) on Windows.

    I've tried using Qt::WindowStaysOnTopHint however this causes the windows to stay above all other windows, even when my app is not in focus. I've also tried setting/unsetting Qt::WindowStaysOnTopHint when the app goes in/out of focus (or manually setting HWND_TOPMOST) but this causes issues with windows getting reordered (not nice for Alt+Tab'ing back to the app).

    Finally, I've also had a go using window parenting. This works nicely for one parent window, however my situation means I have more than one window on the bottom layer, and more than one window that must stay on top.

    Is there a special flag for this that I'm missing? Anyone solved this problem before? Any advice is appreciated.

    1 Reply Last reply
    0
    • IamSumitI Offline
      IamSumitI Offline
      IamSumit
      wrote on last edited by
      #2

      Hi.
      and welcome to Qt devnet
      Have you tried this ->void QWidget::raise () [slot]

      "find here":http://qt-project.org/doc/qt-4.8/qwidget.html#raise

      Be Cute

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gvanvoor
        wrote on last edited by
        #3

        On Mac, you can use the Qt::Tool flag for this, but that doesn't result in this effect on Windows. As suggested, a workaround would consist of raising those windows whenever one that should stay below has been activated.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          patrcki
          wrote on last edited by
          #4

          Thanks for the feedback guys, very much appreciated. Looking at source, it doesn't seem like there's a window flag that maps to WS_EX_PALETTEWINDOW. I'll try using QWidget::raise() and seeing if that can solve the issue.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            patrcki
            wrote on last edited by
            #5

            Just a quick update for anyone interested. I wasn't able to get the behavior I wanted to work correctly with raise(). I ended up using:

            @bool isOnTop = static_cast<QGuiApplication*>(qApp)->applicationState() == Qt::ApplicationActive;
            SetWindowPos(handle, isOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_ASYNCWINDOWPOS | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
            @

            This has to be applied to the windows that need to be on top, in the reverse order they are stacked in.

            The only issue with doing this is that it caused the alt+tab order to be wrong, so I settled with making my always-on-top windows use the Qt::Tool window flags -- this causes them to not appear in the alt+tab list.

            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