From 6290343ce7b9b1facebcb7148fc41f775d9ae5fe Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 5 Feb 2024 12:24:48 +0100 Subject: [PATCH 1/2] Use better resolution of Ayon apps on 4k display Special get_qt_app is used instead of shared get_openpype_qt_app as we don't want to set application icon. --- openpype/hosts/fusion/api/menu.py | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/fusion/api/menu.py b/openpype/hosts/fusion/api/menu.py index 0b9ad1a43b3..53ff5af7672 100644 --- a/openpype/hosts/fusion/api/menu.py +++ b/openpype/hosts/fusion/api/menu.py @@ -173,8 +173,38 @@ def on_set_framerange_clicked(self): set_asset_framerange() +def get_qt_app(): + """Main Qt application.""" + + app = QtWidgets.QApplication.instance() + if app is None: + for attr_name in ( + "AA_EnableHighDpiScaling", + "AA_UseHighDpiPixmaps", + ): + attr = getattr(QtCore.Qt, attr_name, None) + if attr is not None: + QtWidgets.QApplication.setAttribute(attr) + + policy = os.getenv("QT_SCALE_FACTOR_ROUNDING_POLICY") + if ( + hasattr( + QtWidgets.QApplication, "setHighDpiScaleFactorRoundingPolicy" + ) + and not policy + ): + QtWidgets.QApplication.setHighDpiScaleFactorRoundingPolicy( + QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough + ) + + app = QtWidgets.QApplication(sys.argv) + + return app + + def launch_openpype_menu(): - app = QtWidgets.QApplication(sys.argv) + + app = get_qt_app() pype_menu = OpenPypeMenu() From 9452cdb06d289aced41d4bffb0104f6fc24d2ab5 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Mon, 5 Feb 2024 13:45:04 +0100 Subject: [PATCH 2/2] define 'get_qt_app' in tools utils --- openpype/hosts/fusion/api/menu.py | 30 +----------------------------- openpype/tools/utils/__init__.py | 1 + openpype/tools/utils/lib.py | 23 +++++++++++++++++++---- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/openpype/hosts/fusion/api/menu.py b/openpype/hosts/fusion/api/menu.py index 53ff5af7672..ff4a7349283 100644 --- a/openpype/hosts/fusion/api/menu.py +++ b/openpype/hosts/fusion/api/menu.py @@ -15,6 +15,7 @@ ) from openpype.pipeline import get_current_asset_name from openpype.resources import get_openpype_icon_filepath +from openpype.tools.utils import get_qt_app from .pipeline import FusionEventHandler from .pulse import FusionPulse @@ -173,35 +174,6 @@ def on_set_framerange_clicked(self): set_asset_framerange() -def get_qt_app(): - """Main Qt application.""" - - app = QtWidgets.QApplication.instance() - if app is None: - for attr_name in ( - "AA_EnableHighDpiScaling", - "AA_UseHighDpiPixmaps", - ): - attr = getattr(QtCore.Qt, attr_name, None) - if attr is not None: - QtWidgets.QApplication.setAttribute(attr) - - policy = os.getenv("QT_SCALE_FACTOR_ROUNDING_POLICY") - if ( - hasattr( - QtWidgets.QApplication, "setHighDpiScaleFactorRoundingPolicy" - ) - and not policy - ): - QtWidgets.QApplication.setHighDpiScaleFactorRoundingPolicy( - QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough - ) - - app = QtWidgets.QApplication(sys.argv) - - return app - - def launch_openpype_menu(): app = get_qt_app() diff --git a/openpype/tools/utils/__init__.py b/openpype/tools/utils/__init__.py index 50d50f467a6..74702a2a101 100644 --- a/openpype/tools/utils/__init__.py +++ b/openpype/tools/utils/__init__.py @@ -32,6 +32,7 @@ set_style_property, DynamicQThread, qt_app_context, + get_qt_app, get_openpype_qt_app, get_asset_icon, get_asset_icon_by_name, diff --git a/openpype/tools/utils/lib.py b/openpype/tools/utils/lib.py index 365caaafd9b..c7f92dd26e1 100644 --- a/openpype/tools/utils/lib.py +++ b/openpype/tools/utils/lib.py @@ -154,11 +154,15 @@ def qt_app_context(): yield app -def get_openpype_qt_app(): - """Main Qt application initialized for OpenPype processed. +def get_qt_app(): + """Get Qt application. - This function should be used only inside OpenPype process and never inside - other processes. + The function initializes new Qt application if it is not already + initialized. It also sets some attributes to the application to + ensure that it will work properly on high DPI displays. + + Returns: + QtWidgets.QApplication: Current Qt application. """ app = QtWidgets.QApplication.instance() @@ -184,6 +188,17 @@ def get_openpype_qt_app(): app = QtWidgets.QApplication(sys.argv) + return app + + +def get_openpype_qt_app(): + """Main Qt application initialized for OpenPype processed. + + This function should be used only inside OpenPype process and never inside + other processes. + """ + + app = get_qt_app() app.setWindowIcon(QtGui.QIcon(get_app_icon_path())) return app