简体   繁体   中英

Qt + Frameless Window + Compositing

I'm trying to open couple of popup windows (top level), which are frameless. I can achieve this with :

window.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog)

But the problem is that windows, doesn't go through OS compositor (for example on windows they don't have drop shadows). I can achieve windows shadows with Qt.Popup and Qt.ToolTip flags, but both of those have behavior problems, Tooltips are always on top and popups are closed when their focus is lost.

So, is there any way that I could show a frameless window with default OS window manager shadow effect ?

Found a workaround on windows. but I couldn't do it with Qt, so I used win32 hack.
Add this to the QWidget class constructor :

if sys.platform == 'win32':
  import win32api
  win32api.SetClassLong(eval(self.winId().__hex__()), -26, 0x0008 | 0x00020000)

I actually added CS_DROPSHADOW style to the window class styles

It may help for next users to use the Qt.ToolTip flag and avoid having Tooltips always on top.

Python code

self.setWindowFlags(self.windowFlags() | Qt.ToolTip)
self.setWindowFlags(self.windowFlags() & ~Qt.WindowStaysOnTopHint)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM