From 2c0a1dd298d917022c304cae5fafa22984b2ccb9 Mon Sep 17 00:00:00 2001 From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com> Date: Sun, 9 Oct 2022 23:45:53 +0200 Subject: [PATCH] Refactor cursor: pointer event filter --- qt/aqt/__init__.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index 28a404a38..378f058e3 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -345,27 +345,19 @@ class AnkiApp(QApplication): ################################################## def eventFilter(self, src: Any, evt: QEvent) -> bool: + pointer_classes = ( + QPushButton, + QCheckBox, + QRadioButton, + QMenu, + # classes with PyQt5 compatibility proxy + without_qt5_compat_wrapper(QToolButton), + without_qt5_compat_wrapper(QTabBar), + ) if evt.type() in [QEvent.Type.Enter, QEvent.Type.HoverEnter]: - if ( - ( - isinstance( - src, - ( - QPushButton, - QCheckBox, - QRadioButton, - QMenu, - # classes with PyQt5 compatibility proxy - without_qt5_compat_wrapper(QToolButton), - without_qt5_compat_wrapper(QTabBar), - ), - ) - ) - and src.isEnabled() - or ( - isinstance(src, without_qt5_compat_wrapper(QComboBox)) - and not src.isEditable() - ) + if (isinstance(src, pointer_classes) and src.isEnabled()) or ( + isinstance(src, without_qt5_compat_wrapper(QComboBox)) + and not src.isEditable() ): self.setOverrideCursor(QCursor(Qt.CursorShape.PointingHandCursor)) else: