jupyter/qtconsole

Qtconsole quits when trying to drag in PyQt6

dschueler-exos opened this issue ยท 12 comments

I'm on an Apple Silicon Mac, running Ventura 13.5 (also confirmed on an Intel Mac running Big Sur 11.7.9), and in jupyter qtconsole, whenever I select a bit of text and then click and hold the mouse as if to drag that text somewhere, the console aborts.

I couldn't reproduce this in PyQt5, but it looks as if there may have been changes in PyQt6 that need addressing. If I try to drag a selection in qtconsole 5.4.3, I get the following:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/opt/miniconda3/envs/pyqt6/lib/python3.9/site-packages/qtconsole/console_widget.py:400, in ConsoleWidget.dragMoveEvent(self, e)
    398     pass
    399 elif e.mimeData().hasText():
--> 400     cursor = self._control.cursorForPosition(e.pos())
    401     if self._in_buffer(cursor.position()):
    402         e.setDropAction(QtCore.Qt.CopyAction)

AttributeError: 'QDragMoveEvent' object has no attribute 'pos'

2023-08-08 13:51:08,444 - ERROR - Exception in GUI event loop
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/opt/miniconda3/envs/pyqt6/lib/python3.9/site-packages/qtconsole/console_widget.py:400, in ConsoleWidget.dragMoveEvent(self, e)
    398     pass
    399 elif e.mimeData().hasText():
--> 400     cursor = self._control.cursorForPosition(e.pos())
    401     if self._in_buffer(cursor.position()):
    402         e.setDropAction(QtCore.Qt.CopyAction)

AttributeError: 'QDragMoveEvent' object has no attribute 'pos'

2023-08-08 13:51:16,031 - ERROR - Exception in GUI event loop
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/opt/miniconda3/envs/pyqt6/lib/python3.9/site-packages/qtconsole/console_widget.py:400, in ConsoleWidget.dragMoveEvent(self, e)
    398     pass
    399 elif e.mimeData().hasText():
--> 400     cursor = self._control.cursorForPosition(e.pos())
    401     if self._in_buffer(cursor.position()):
    402         e.setDropAction(QtCore.Qt.CopyAction)

AttributeError: 'QDragMoveEvent' object has no attribute 'pos'

According to https://stackoverflow.com/questions/67496362/qmouseevent-object-has-no-attribute-pos, the fix may be as simple as changing e.pos to e.position, or at least catching the AttributeError and switching to the correct attribute. This will need a little looking into.

By the way, if your whole application aborts with this bug, then you might be experiencing the issue discussed here. Customizing sys.excepthook in qtconsole might be worth thinking about, although it might interfere with other applications using the library. Such errors should produce an exception, not a core dump.

I am indeed on PyQt6, on both machines. And thanks for taking a look!

the fix may be as simple as changing e.pos to e.position

I think this case is already covered in Qtpy so the code is compatible between Qt5 and 6, right @dalthviz?

I think some handling was added but only for QMouseEvent at spyder-ide/qtpy#408 and in general all the child classes of QSinglePointEvent at spyder-ide/qtpy#417

Thanks for checking @dalthviz.

@rayosborn, then a fix for this would require adding to Qtpy something similar to spyder-ide/qtpy#408 for QDragMoveEvent.

Hi, just in case, updating to QtPy 2.4.0 should fix this issue (at least the issues/traceback related with the drag and drop event)

Thanks @dalthviz! I'll bump our QtPy requirement and release a new Qtconsole version shortly so the fix can reach more users.

Hi, just in case, updating to QtPy 2.4.0 should fix this issue (at least the issues/traceback related with the drag and drop event)

That worked. Thanks!

Just for the record, upgrading to QtPy v2.4.0 does indeed fix the issue in NeXpy when using PyQt6. @dalthviz, thanks for the fix! I'll update our dependencies.

I released 5.4.4 with an increased requirement on QtPy.