createWindowContainer + QWindow.fromWinId
-
HI,
Good morning! Im a spanish developer using my own compiled libraries of PyQt5 and Qt5.
Im trying to create a widget that wraps around some third party windows app called DaVinci Resolve.
This method im using is working fine for other softwares like Blender, etc. But for some reason with this one, Resolve 17 there is a problem.
The problem consists of all the widgets correctly placed after the native app window has been wrapped but the painting and rendering has an offset of some pixels from the top and the right side. This causes that the tool bar menu shows up some pixels down where the funcionality "really is".See attached image.

This is what im doing:hwnd = win32gui.FindWindow(None, K_WINDOW_NAME) window = QWindow.fromWinId(hwnd) widget = QWidget.createWindowContainer(window)
-
Hi and welcome to devnet,
If memory serves well, it used to be built with Qt so can you test if you have the same issue with a Qt application ?
-
Hi!
Will try what you say @SGaist thank you very much!
In the meantime, this is what ive achieved so far:
I've managed to embed the app into a QApplication QMainWindow but as you can see on the right side of the screen there is an empty room of 400 px where it is supposed to paint and render my custom widget.Find here attached the screen grab.
(
My question is, why is it not rendering it?
Im calling "show" and "processEvents()" on the embedding QApplication and im relying on the HBoxLayout to property position the widgets. -
Hi @SGaist ,
ive come to new conclusions regarding the first question that opened the topic.
If i launch DaVinci Resolve as a subprocess through a python script first and then wait for the main app native window to show up it works correctly (as shown in the following picture)Which leads me to the conclusion that the place where im calling the methods below:
hwnd = win32gui.FindWindow(None, K_WINDOW_NAME) window = QWindow.fromWinId(hwnd) widget = QWidget.createWindowContainer(window)
which is in a "startup" script that Resolve finds to autoexecute stuff OnOpen isnt the right place to do it. Or at least, the way it is being launched is not correct. This is through a "<name>.scriptlib" LUA script and it is supposed to be run on Resolve Startup.
-
Sounds like you could be getting the handle too early and it breaks the UI setup. Do you have a hook you can use to trigger your code a bit later ?
-
Hi @SGaist ,
Thanks for the hint.
i tried to put some time.sleep(10.0) before performing all the stuff and creating the QApplication and i still have the black frames on the top and right side of the window handle.
Throwing a guess in the air, could it be possible that that black space is reserved for App Menu Tool bar and that the right side is reserved for a native scrollbar? If so, how is this like this? how can i deactivate it? I tried to wrap a QWidget around the notepad.exe in windows 11 and i got similar strange behaviour. All the toolbar menus go black except for a single icon. This makes sense to me. The width of the right side black space looks like if a scrollbar was missing there. Again, just a guess. Does this resonate with you? -
Hi!
i managed to sort it out, finnally!
The trick was to discover that resolve has an option for the UI to go fullscreen. When entering that mode, the black space would be gone but this time the tool bar menu would be misplaced offscreen.
A further investigation led to the fact that in this mode, resolve' main native window has no longer the same window name (a look with spy++.exe shed some light here).
So all i have to do now is to find a way to programmatically enter fullscreen mode and wrap the qt widget around this new window... Or, option 2, by using this windows api call:win32gui.SetWindowLong(hwnd, win32con.GWL_STYLE, win32con.WS_POPUPWINDOW | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.WS_SIZEBOX | \ win32con.WS_MAXIMIZEBOX | win32con.WS_MINIMIZEBOX | win32con.WS_CLIPCHILDREN)
this would disable the menu tool bar of the main window which is what was provoking this black space.
Either case, it is working now.See here attached image:
-
Glad you found out and thanks for sharing !