pyside6_qtads
pyside6_qtads copied to clipboard
QWidget::windowHandle() call raises RuntimeError exception
Hi there, Thank you for the work you've done already. I really appreciate it.
Recently, I wanted to use this PySide6 port of QT ADS for my project, and bumped into an exception.
Traceback (most recent call last):
File "C:\Users\jakej\Documents\workspace\pythonPlayground\venv\lib\site-packages\matplotlib\backends\backend_qt.py", line 495, in _draw_idle
if self.height() < 0 or self.width() < 0:
File "C:\Users\jakej\Documents\workspace\pythonPlayground\venv\lib\site-packages\matplotlib\backends\backend_qt.py", line 262, in showEvent
window.screenChanged.connect(self._update_screen)
RuntimeError: Internal C++ object (PySide6.QtGui.QWindow) already deleted.
I was using matplotlib chart in the dock.
The code that raised exception was following.
venv/Lib/site-packages/matplotlib/backends/backend_qt.py
def showEvent(self, event):
# Set up correct pixel ratio, and connect to any signal changes for it,
# once the window is shown (and thus has these attributes).
window = self.window().windowHandle()
window.screenChanged.connect(self._update_screen)
self._update_screen(window.screen())
I investigated the code and found following. When I changed the code like this, it worked.
def showEvent(self, event):
# Set up correct pixel ratio, and connect to any signal changes for it,
# once the window is shown (and thus has these attributes).
dummy = self.window() # <=== This is the code I inserted
window = self.window().windowHandle()
window.screenChanged.connect(self._update_screen)
self._update_screen(window.screen())
However, I don't want to modify the code in matplotlib.
So I investigate more and suspected that the return value from QWidget.windowHandle() might be lost.
Finally I tried inserting following line in bindings.xml
.
<object-type name="CFloatingDockContainer">
<!-- ... -->
<declare-function signature="windowHandle()" return-type="QWindow"/>
<!-- ... -->
</object-type>
It works!
But I'm not sure if this correction is the way shiboken suggests because I'm not familiar with shiboken.
And I don't know the exact mechanism why this should be added though CFloatingDockContainer
inherits QWidget
.
The fact that a macro definition was used might make shiboken confusing.
#include <QWidget>
#define tFloatingWidgetBase QWidget
Could you please look into this issue and clarify what the root cause of it?
Or we can just settle down on this declare-function
solution.
Thank you for giving your precious attention on reading this issue.
Best regards, Jake