Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken axes (misaligned) on dual screen [Bug] #101

Open
blupgnup opened this issue Jul 10, 2024 · 2 comments
Open

Broken axes (misaligned) on dual screen [Bug] #101

blupgnup opened this issue Jul 10, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@blupgnup
Copy link

Version

Development

What is affected by the bug?

Any GUI that plots graph and display axes when using dual screen computer.

When does the bug occur?

When using qudi-core on a computer with 2 screens of different size, a known bug of PySide2 leads to misaligned axis when plotting a graph.
This is mainly due to Windows HighDPI scaling.

How do we replicate the issue?

Create a GUI that plots a graph using a class inheriting QtWidgets.QMainWindow
Launch qudi on a dual screen computer with 2 screens using different windows display scaling.
Move the GUI on the second screen, the axes will appear completely misaligned although the plot is still ok.

Expected behavior

Axes should remain aligned for a better viewing and especially because, in this case, the data plotted is also not in phase with axes.

Relevant log output

No response

Additional Comments

The following code can fix this issue by making the program "DPI aware".
import platform
import ctypes
if platform.system()=='Windows' and int(platform.release()) >= 8:
ctypes.windll.shcore.SetProcessDpiAwareness(True)

However, it is not possible to use this fix in a qudi module as it needs to run before the main GUI initialization.
Was tested successfully by making this change in src\qudi\core\gui\gui.py

There could also be some more 'proper' way to do it using QTAttribute:
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
but this did not work in my case...

In any case, if the proposed solution is acceptable, it would be great to have it integrated into qudi-core to avoid working with a modified version and I think this could benefit many users facing the same problem.

Contact Details

No response

@blupgnup blupgnup added the bug Something isn't working label Jul 10, 2024
@Neverhorst
Copy link
Member

Hi @blupgnup,

thank you for raising this issue.
Just to give more context, I like to point out a subtle difference when it comes to multi-monitor setups under MS Windows:

  • If you are running multiple monitors with different native resolutions and no additional scaling via Windows display settings, you should not encounter any problems (except for occasional weird file dialog display issues). This issue has been resolved a while ago by automatically setting the environment variable QT_ENABLE_HIGHDPI_SCALING before running qudi.

  • Setting multiple different scaling factors in the Windows display settings is a whole different beast and influences Qt5 and qudi in other ways. I think this has not yet been thoroughly tested. We will try to replicate this issue and see if it makes sense to include your proposed DLL call in qudi-core.

@blupgnup
Copy link
Author

Hi @Neverhorst,

Thanks for pointing out the QT_ENABLE_HIGHDPI_SCALING and the link with display scaling.
This actually lead me to another solution to resolve this issue.

Here is the result of some additional tests:

  • Setting up multiple monitors with different native resolution and no additional scaling does, indeed, not raise this issue.
    It is just sometimes not possible when screen resolution are too different (which is why windows introduced display scaling)

  • Setting up multiple monitors with different scaling does raise the issue.
    The problem is always appearing on the second screen no matter what the scaling is (as long as it is different from the main screen).
    Same scaling on both screen (no matter if it is 100% or 125%) does not raise the issue.

  • First possible workaround, introcing the dll code in qudi-core.
    This works with every scaling but does introduce another 'classic' windows problem which is a bit of a blurry effect on the window that is not on the main screen. (kind of documented here : https://support.microsoft.com/en-us/topic/windows-scaling-issues-for-high-dpi-devices-508483cd-7c59-0d08-12b0-960b99aa347d)
    A way to fix this is to use the windows option "High DPI scaling override" and choose "Application" to perform scaling.
    image
    Turns out, this last fix actually also solves the misaligned axis issue, hence removing the necessity of the DLL call!
    My guess is that because it bypasses the "windows scaling", it is actually the same as having both screens without additional scaling...

In conclusion, the DLL call, ensure that this is working without user specific action but at the cost of a slightly blurred window (and maybe unwanted side effects).
A better way to fix it is by overriding the High DPI scaling of python under windows but requires user awareness of the existence of this option... Or to disable display scaling completely.
I am totally fine with closing this issue without adding the DLL call as it works and is less invasive (also I hate this blurry problem that windows still can't properly solve) but I am not sure what would be the best option for other users...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants