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

axis and glyph scaling issue with Multiple DPI monitors #756

Closed
dvincentwest opened this issue Sep 4, 2018 · 29 comments · Fixed by #1509
Closed

axis and glyph scaling issue with Multiple DPI monitors #756

dvincentwest opened this issue Sep 4, 2018 · 29 comments · Fixed by #1509
Assignees
Labels
bug hidpi Issues involving HiDPI monitors and display scaling.

Comments

@dvincentwest
Copy link

dvincentwest commented Sep 4, 2018

I am happy to check this out, but I don't really know where to start.

I am running Windows10, Anaconda x64, python 3.6.6, and the below images were created using the latest git version of pyqtgraph, and PyQt5.9

I have two monitors, one at 1080p (set to 100% scaling) and the other at 4K (set to 150% scaling), and when switching between the two monitors windows will attempt to adjust their scaling accordingly. Some applications do this better than others, and this may in fact be an issue in Qt, but in case we can address it in the pyqtgraph code, that would probably be good.

The first image is on the 1080p monitor and the second is just from moving the window over to the 4K monitor. The problem is most easily seen in the gray plots in the upper left and lower right. You can see that the scatter clouds are centered at 0,0 in the 1080p plots, but are shifted to lower x and higher y coordinates in the 4k 150% plots. This is the major issue because it means the plots aren't accurate in presenting the coordinates of the data.

Weirdly, it also seems that some of the glyphs are shrinking while others are growing when the dpi change happens

Lastly, I can confirm that if I switch the 1st monitor to 150% scaling before starting python, this issue does not happen. It is only an issue when switching from a monitor at one dpi setting to a different one

1080p, 100% Scaling

image

4K, 150% Scaling

image

@dvincentwest dvincentwest changed the title axis scaling issue with Multiple DPI monitors axis and glyph scaling issue with Multiple DPI monitors Sep 4, 2018
@cosminpolifronie
Copy link

I'm having the same problem. Description can be found here.
unitbvcv/image_processing_platform#14

I am trying to fix this in pyqtgraph, but I cannot find the place where the grid is getting drawn. Can anybody help with that?

@j9ac9k
Copy link
Member

j9ac9k commented Jun 25, 2019

@dvincentwest thanks so much for the screen shots, they really illustrate what's happening, only machine I have with a 4k monitor is a laptop I only periodically use and don't have a development environment setup; but I'll try and reproduce the issue there.

@cosminpolifronie if you're still trying to solve this issue, could you see if you can recreate it when installing from the develop branch?

@j9ac9k j9ac9k self-assigned this Jun 25, 2019
@cosminpolifronie
Copy link

@j9ac9k Yup, I can still recreate it using pyqtgraph-0.11.0.dev0+g78df356

@j9ac9k
Copy link
Member

j9ac9k commented Jun 26, 2019

Thanks for reporting back, I'll look into it in the next day or so hopefully

@j9ac9k
Copy link
Member

j9ac9k commented Jun 26, 2019

@cosminpolifronie Thanks again for putting the effort to re-verify. It might be a bit before you get to it, if you're waiting for this, and have a few minutes, could you try inserting the following lines

        QtGui.QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
        if hasattr(QtWidgets.QStyleFactory, "AA_UseHighDpiPixmaps"):
            QtGui.QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

right before this line here:

QAPP = QtGui.QApplication([])

If you're not comfortable editing the source of the library that's fine, I'll get to it.

@cosminpolifronie
Copy link

I have added the lines you suggested, but the bug is not fixed (I've tried to add them before the if on line 335, that didn't help either). I don't think it has to do only with Qt scaling, something is weird in the backend as well.

Look at the following video: https://youtu.be/X4ltNIjDuz4
Second screen only: https://youtu.be/uViX3zOAXIo

The first screen that I'm opening the app in is the main screen with 125% scaling (2560x1440), and the second one has 100% scaling (1920x1080). You can see that when I'm dragging the plot on the second screen, the background grid moves at a different speed. That shouldn't happen.

@j9ac9k
Copy link
Member

j9ac9k commented Jun 26, 2019

Thanks for the videos highlighting this issue I completely understand the problem; I've assigned myself some issues and I have some PRs to review first, but I'll poke around with this... Do you have any suggestions on how we can make a test that will actually fail for this issue?

@cosminpolifronie
Copy link

Can this be automatically tested, as it is a display error? Do we have any means to probe into the actual displayed elements (as in pixels, maybe)?

@j9ac9k
Copy link
Member

j9ac9k commented Jun 26, 2019

If I was to characterize this, I would say that during a drag event, the mouse does not remain at the same coordinates within the view.

First step is definitely to make a test that simulates a mouse drag event (there are other tests in the test suite that do this) and we can show that the mouse position within the view did not remain the same. What I don't know how to do in the test suite is to capture the monitor scaling that's occurring.

@cosminpolifronie
Copy link

cosminpolifronie commented Jun 26, 2019

I don't have any kind of experience with testing, so I'll have to learn to be helpful. Tomorrow I'll have my last exam before I finish university, and after that I could look into it.

It could take a while, but I'm willing to learn.

the mouse does not remain at the same coordinates within the view

I don't understand. Are we talking about the same issue?

@j9ac9k
Copy link
Member

j9ac9k commented Jun 26, 2019

I don't understand. Are we talking about the same issue?

In your video, when you click on drag, the mouse stays in the same position, relative to the grid on the right monitor, but on the left monitor the mouse position moves in relation to the grid. Is that not the issue you're describing?

@cosminpolifronie
Copy link

cosminpolifronie commented Jun 26, 2019

Oooh, I didn't look at it this way. Yes, it is one problem, but there are others: the plot is badly represented in height (it's shifted downwards), and the plot and the grid move out of sync (they move at different speeds, the grid stays sychronized to the mouse movement while the plot does not and "floats"). Basically, when you move the plot, the x and y values change as you move the plot, they don't stay linked to their corresponding values on the grid.

@Kheirlb
Copy link

Kheirlb commented Aug 14, 2019

I'm experiencing a similar bug. Any new news on how to fix it? However its more along the lines of #795

@j9ac9k
Copy link
Member

j9ac9k commented Oct 18, 2019

@cosminpolifronie @Kheirlb

An item in the changelog for Qt 5.13.1 caught my attention that may be relevant:

****************************************************************************
*                                  QtGui                                   *
****************************************************************************

 - [QTBUG-73231] QWindow::mapToGlobal()/mapFromGlobal() now handle windows
   spanning screens correctly.

I would be eager to get an update on this issue if either of you install either PySide2 5.13.1 or PyQt 5.13.1 and report back.

Thanks

@cosminpolifronie
Copy link

Sadly the bug is still there with PyQt 5.13.1 😢.

@james0807
Copy link

I'm seeing something similar (I think), viewing a plot on a 4k display with 250% scaling, the line in the plot seems to become discontinuous? I'll try to upload a screenshot soon.

@Schneider1
Copy link

I have the same problem and here's what I see:

  • This is independent of 4K resolution, it appears when you have two screens with different scaling (even if the resolution is the same)
  • On the main screen, the view is always correct, the problem only occurs on the extended screen
  • When you drag the window between the screens, you see that the axis size and labels change as soon as the center of the windows is on the extended screen; the rest (data and titlebar etc.) stay at the same size
  • The axes still show the correct range, but are just smaller than the data
    125screen
    100screen
    The first image shows the situation on the main screen (125% scaling), the second image shows the extended screen (100% scaling)

Code snippet

import numpy as np
import pyqtgraph as pg

data = np.random.normal(size=1000)
pg.plot(data, title="test")
pg.QtGui.QApplication.exec_()

@andybarry
Copy link

I was able to fix this issue by adding:

QApplication.setAttribute(QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)

after the imports in your example.

Here's a relevant mailing list post: https://lists.qt-project.org/pipermail/development/2019-September/037434.html

Working example:

from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5 import QtCore

import numpy as np
import pyqtgraph as pg

QApplication.setAttribute(QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)

data = np.random.normal(size=1000)
pg.plot(data, title="test")
pg.QtGui.QApplication.exec_()

@j9ac9k
Copy link
Member

j9ac9k commented Jun 12, 2020

@andybarry Thank you so much for sharing!

If I'm reading it right, this was introduced in Qt 5.14, so this will only work on newer versions of Qt, but I see no reason not to add this to pg.mkQApp() with an if check for Qt version.

@j9ac9k j9ac9k added the hidpi Issues involving HiDPI monitors and display scaling. label Jun 13, 2020
@luiztauffer
Copy link

@andybarry solution makes my app blurry and fonts too small... has anyone managed to find a solution for this?

@j9ac9k
Copy link
Member

j9ac9k commented Jul 2, 2020

@luiztauffer I've self-assigned hidpi issues as I have a windows laptop w/ a hidpi monitor and an external non-hidpi display I can test on. I'm not sure when I'm going to get to it, or if I'm going to be able to find a solution. My first priority is working on the PR backlog (we're down to 30-something from 180 a year ago!).

That said, this matplotlib issue may be of relevance, they identified a fix, but I think it requires Qt 5.15+

matplotlib/matplotlib#17440

If you implement their fix, please do report back!

@andybarry
Copy link

Another option: https://stackoverflow.com/a/48431398/730138

@Androwei
Copy link

Androwei commented Oct 9, 2020

I had the same problem (Windows 10 , display scale to 125%, Python3.7, pyqtgraph 0.11, PySide2 5.15.1).

This solution works for me.
PySimpleGUI/PySimpleGUI#1179

you can make your app DPI-aware by using the following code before you load any GUI elements:

import ctypes
import platform


def make_dpi_aware():
    if int(platform.release()) >= 8:
        ctypes.windll.shcore.SetProcessDpiAwareness(True)

And running this somewhere in your code:

make_dpi_aware()

I run this function before QApplication.

@j9ac9k
Copy link
Member

j9ac9k commented Jan 23, 2021

def make_dpi_aware():
if int(platform.release()) >= 8:
ctypes.windll.shcore.SetProcessDpiAwareness(True)

I'm working on #1509 and I tried implementing this, but this seemed to make text in the example app blurry (on Qt 5.12)... lots of combinations to try out over here still...

@RitterD
Copy link

RitterD commented Jan 27, 2022

for PySide2 with Qt-Version 5.15 I was able to fix this by adding the following two lines before app = QApplication(sys.argv)

QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)

I hope I can help some ppl out with that.
With setAttribute as @andybarry suggested it wasnt possible for me and after the windll manipulation the app became blurry

@ozankececioglu
Copy link

Thanks for sharing @RitterD, this also fixes our long standing issue here. Cheers!

@HoWeBrz
Copy link

HoWeBrz commented Feb 18, 2022

I downloaded the latest pyqtgraph version 0.12.3 from git (pip install git+https://github.com/pyqtgraph/pyqtgraph.git) and expected this issue to be solved.
But I still see the issue in the bad scaling (e.g. in the pymeasure ManagedWindow example) , when my Windows display setting is set to something else as 100%.

What package do I have to install to get it fixed (beginner skill on myside ;-) )?

@karahanyilmazer
Copy link

By combining this code and this I get good-looking plots with a multi-dpi setting with different scalings. But the solution is very lengthy to include in the beginning of every script. I would very much appreciate a proper fix.

import ctypes
import platform
import sys
import matplotlib.pyplot as plt
from IPython import get_ipython

if int(platform.release()) >= 8:
    ctypes.windll.shcore.SetProcessDpiAwareness(True)
        
if get_ipython() is not None:
    get_ipython().run_line_magic('matplotlib', 'qt')

if plt.get_backend() == 'Qt5Agg':
    from matplotlib.backends.qt_compat import QtWidgets
    qApp = QtWidgets.QApplication(sys.argv)
    plt.matplotlib.rcParams['figure.dpi'] = qApp.desktop().physicalDpiX()

@HoWeBrz
Copy link

HoWeBrz commented Mar 15, 2022

@karahanyilmazer I can confirm, that this workaround works for me and I get proper scaling with non-100% dpi-scaling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug hidpi Issues involving HiDPI monitors and display scaling.
Projects
None yet
Development

Successfully merging a pull request may close this issue.