Search code examples
qtuser-interfacepyqtwin32guirainmeter

How to make pyqt app stay on bottom of all windows like Rainmeter?


I need to have my window stay on bottom. I tried using WindowStaysOnBottomHint but when Win+D or Show Desktop is clicked the app minimizes.

I researched and found that Rainmeter reorders the Z-index when Show Desktop is clicked using Win32 Api SetWindowPos but I am unable to find a solution for python QT.

Please give me solution!!


Solution

  • I found the solution using win32 API for python (Only for windows) . Refer SetWindowPos, SetWindowLong, win32gui

    if sys.platform=='win32':
        from ctypes import windll
        import win32gui,win32con
        win32gui.SetWindowPos(window.winId(),win32con.HWND_BOTTOM, 0,0,0,0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE  | win32con.SWP_NOACTIVATE )
    
        hwnd=win32gui.GetWindow(win32gui.GetWindow(windll.user32.GetTopWindow(0),win32con.GW_HWNDLAST),win32con.GW_CHILD);
        win32gui.SetWindowLong(window.winId(),win32con.GWL_HWNDPARENT,hwnd)
    

    window is the QTWidget window