High DPI scaling issue when running napari from PyCharm console

After a day long struggle, I am getting close to working with napari from PyCharm. The last (?) issue is that when I start the QT loop in the PyCharm terminal with:

%gui qt

and start the napari viewer with:

import napari
viewer = napari.view_image()

I end up with a viewer that is “scaled wrong” (starting the QT loop with “with napari.gui_qt():” works correctly, but does not let me work with the viewer object). Searching for this problem brought me to: https://github.com/napari/napari/pull/820 which fixes exactly this problem. In that PR @talley described that his fix was pushed upstream into IPython. Pycharm (2020.2.3) is running IPython 7.18.1 (not sure if that comes from my environment or from Pycharm), which was released August 29, 2020, so I assume that it contains the fix. Is there anything I can/should do in the console to “activate” the correct scaling?

B.t.w., when I run IPython directly, and run the same code as above, napari display scales correctly, which seems to suggest that the problem is in PyCharm. Is anyone aware of PyCharm settings that I need to change, or anything else to solve this?


Figured it out (leaving this here in case anyone else runs into the same problem):

Add the environment variable “QT_ENABLE_HIGHDPI_SCALING=1” to:
PyCharm menu > File > Settings > Build, Execution, Deployment > Console > Environment Variables


Glad you figured that out, and thanks for making the issue and documenting it here! I know we’ve struggled with this in the past!!