spyder-ide / qtawesome

Iconic fonts in PyQt and PySide applications
https://qtawesome.readthedocs.io/en/latest/index.html
MIT License
802 stars 105 forks source link

qta-browser with PySide6 #170

Closed kumattau closed 2 years ago

kumattau commented 2 years ago

Hi, qtpy supported PySide6 in master branch. So I am trying qta-browser with PySide6.

I found some issues and informed them to the corresponding project.

But, besides the above, it is left that QApplication.desktop(), which is used in icon_browser.py, is missing.

https://github.com/spyder-ide/qtawesome/blob/a30d520d41d31c23c571ec768eb39bd4df66fdb9/qtawesome/icon_browser.py#L95

About QApplication.desktop(), which component should be fixed ?

kumattau commented 2 years ago

Additional Information:

QDesktopWidget class returned by QApplication.desktop() has been removed in Qt6.

https://doc.qt.io/qt-6/widgets-changes-qt6.html#qdesktopwidget-and-qapplication-desktop

QDesktopWidget was already deprecated in Qt 5, and has been removed in Qt 6, together with QApplication::desktop().

QScreen provides equivalent functionality to query for information about available screens, screen that form a virtual desktop, and screen geometries.

Use QWidget::setScreen() to create a QWidget on a specific display; note that this does not move a widget to a screen in a virtual desktop setup.

ccordoba12 commented 2 years ago

@kumattau, you're welcome to remove the usage of QApplication.desktop() and replace it with QScreen instead. We don't have a problem with that.

kumattau commented 2 years ago

@ccordoba12 , thank you for the reply.

I'm sorry that I forget that QSortFilterProxyModel.setFilterRegExp() has been removed in Qt 6. I think setFilterRegularExpression() can be used instead.

There is difference between QRegExp and QRegularExpression, but I think it has almost no effect in the qta-browser usage.

https://doc.qt.io/qt-5/qregularexpression.html#notes-for-qregexp-users

I am preparing PR to fix QApplication.desktop() and QSortFilterProxyModel.setFilterRegExp().

QApplication.desktop() and replace it with QScreen instead.

Can I simply replace it ? Or do I need to support qt 5.10 or earlier as follows ?

diff --git a/qtawesome/icon_browser.py b/qtawesome/icon_browser.py
index 19399af..ea11916 100644
--- a/qtawesome/icon_browser.py
+++ b/qtawesome/icon_browser.py
@@ -92,9 +92,17 @@ class IconBrowser(QtWidgets.QMainWindow):
         self._lineEdit.setFocus()

         geo = self.geometry()
-        desktop = QtWidgets.QApplication.desktop()
-        screen = desktop.screenNumber(desktop.cursor().pos())
-        centerPoint = desktop.screenGeometry(screen).center()
+
+        # QApplication.desktop() has been removed in Qt 6.
+        # Instead, QGuiApplication.screenAt is supported in Qt 5.10 or later.
+        try:
+            desktop = QtWidgets.QApplication.desktop()
+            screen = desktop.screenNumber(desktop.cursor().pos())
+            centerPoint = desktop.screenGeometry(screen).center()
+        except:
+            screen = QtGui.QGuiApplication.screenAt(QtGui.QCursor.pos())
+            centerPoint = screen.geometry().center()
+
         geo.moveCenter(centerPoint)
         self.setGeometry(geo)

@@ -113,7 +121,13 @@ class IconBrowser(QtWidgets.QMainWindow):
         if searchTerm:
             reString += ".*%s.*$" % searchTerm

-        self._proxyModel.setFilterRegExp(reString)
+        # QSortFilterProxyModel.setFilterRegExp has been removed in Qt 6.
+        # Instead, QSortFilterProxyModel.setFilterRegularExpression is
+        # supported in Qt 5.12 or later.
+        try:
+            self._proxyModel.setFilterRegExp(reString)
+        except:
+            self._proxyModel.setFilterRegularExpression(reString)
ccordoba12 commented 2 years ago

Can I simply replace it ? Or do I need to support qt 5.10 or earlier as follows ?

Please support older than 5.10 Qt versions.

dalthviz commented 2 years ago

@kumattau just in case I merged spyder-ide/qtpy#254 :+1:

kumattau commented 2 years ago

@ccordoba12 @dalthviz many thanks. I sended PR #171. It's just same as above patch. (the fix of PySide6 QFont problem is added)