Repository: spyder-ide/qtpy (language: python)

Issue:
Some compatibility issues when using latest PyQt6 or PySide6 (6.5+)
Checking around seems like the latest version of the Qt 6 bindings (6.5.2 I think) come with some changes (related with deprecations) that can cause some errors. Some examples:

* https://github.com/napari/napari/issues/6060
* https://github.com/napari/napari/issues/6135
* https://github.com/napari/napari/pull/5986#issuecomment-1669867592 (`Qt.ItemFlags` vs `Qt.ItemFlag` - PyQt6)
* https://github.com/jupyter/qtconsole/issues/583#issuecomment-1670130291 (`QDragMoveEvent.pos` vs `QDragMoveEvent.position`)

I think it could be worthy to check if something from the QtPy side could be done and include it in v2.4.0. Also, testing on the CI with Qt 6.5 seems worthy and could help us see if there are any other errors/changes to be done.

Other relevant related work in progress: 

* https://github.com/spyder-ide/spyder/pull/21227#issuecomment-1668211205

What do you think @ccordoba12 @CAM-Gerlach ?


Discussion / hints:
If we can help to provide more compatibility with Qt6, I'm ok with it.

Fix patch:
diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py
index 6dbeec2e..ebb1d87b 100644
--- a/qtpy/QtWidgets.py
+++ b/qtpy/QtWidgets.py
@@ -71,6 +71,9 @@ def _directory_to_dir_(*args, **kwargs):
     QMenu.exec_ = lambda *args, **kwargs: possibly_static_exec(QMenu, *args, **kwargs)
     QLineEdit.getTextMargins = lambda self: (self.textMargins().left(), self.textMargins().top(), self.textMargins().right(), self.textMargins().bottom())
 
+    # Map missing flags definitions
+    QFileDialog.Options = QFileDialog.Option
+
     # Allow unscoped access for enums inside the QtWidgets module
     from .enums_compat import promote_enums
     promote_enums(QtWidgets)


Test patch:
diff --git a/qtpy/tests/test_qtwidgets.py b/qtpy/tests/test_qtwidgets.py
index 2858a3f3..203c11b7 100644
--- a/qtpy/tests/test_qtwidgets.py
+++ b/qtpy/tests/test_qtwidgets.py
@@ -155,7 +155,7 @@ def test_opengl_imports():
     reason="Crashes on macOS with Python 3.7 with 'Illegal instruction: 4'")
 @pytest.mark.parametrize("keyword", ["dir", "directory"])
 @pytest.mark.parametrize("instance", [True, False])
-def test_qfiledialog_compat(tmp_path, qtbot, keyword, instance):
+def test_qfiledialog_dir_compat(tmp_path, qtbot, keyword, instance):
     """
     This function is testing if the decorators that renamed the dir/directory
     keyword are working.
@@ -229,4 +229,11 @@ def run(self, allow_restart=True):
     qtbot.waitUntil(thr.isRunning, timeout=1000)
     dlg = QtWidgets.QFileDialog() if instance else QtWidgets.QFileDialog
     dlg.getExistingDirectory(**kwargs)
-    qtbot.waitUntil(thr.isFinished, timeout=3000)
\ No newline at end of file
+    qtbot.waitUntil(thr.isFinished, timeout=3000)
+
+
+def test_qfiledialog_flags_typedef():
+    """
+    Test existence of `QFlags<Option>` typedef `Options` that was removed from PyQt6
+    """
+    assert QtWidgets.QFileDialog.Options is not None