Skip to content

ScatterPlotItem: implement hidpi pixmap#2863

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:scatter-hidpi
Nov 2, 2023
Merged

ScatterPlotItem: implement hidpi pixmap#2863
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:scatter-hidpi

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Oct 30, 2023

This PR came about while investigating #2854.
Although a workaround for #2854 was to disable useCache, the true reason for the blurriness on hidpi displays is due to the pixmap atlas only being rendered at a dpi of 1.0.

  1. The improved sharpness of this PR vs master (on a hidpi display) can be seen from the ScatterPlot.py, Symbol.py examples.
  2. On a hidpi display, this PR achieves a higher frame-rate than master on ScatterPlotSpeedTest.py. i.e. there is a drawing penalty when a lo-res pixmap needs to be scaled to be painted onto a hidpi display.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 31, 2023

I think you can programatically get that ratio you need by doing the following inside the paint method

dpi = self.getViewWidget().metric(QtGui.QPaintDevice.PaintDeviceMetric.PdmPhysicalDpiX)
pixmap_dpi = self.fragmentAtlas.pixmap.metric(QtGui.QPaintDevice.PaintDeviceMetric.PdmPhysicalDpiX)

scale = dpi / pixmap_dpi

Likely don't want to be calling this during every paint call...

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Oct 31, 2023

I think you can programatically get that ratio you need by doing the following inside the paint method
dpi = self.getViewWidget().metric(QtGui.QPaintDevice.PaintDeviceMetric.PdmPhysicalDpiX)
pixmap_dpi = self.fragmentAtlas.pixmap.metric(QtGui.QPaintDevice.PaintDeviceMetric.PdmPhysicalDpiX)
scale = dpi / pixmap_dpi

Although we call it "hi-dpi", the quantity that we are interested in is the DPR rather than the DPI.

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Nov 1, 2023

As a bonus, this PR also fixes the following artifacts that appear for the bottom right plot of ScatterPlot.py example the moment the mouse is moved over it.
(Windows 10 device pixel ratio 1.25, PySide6 6.6.0)
before_br

Even without a display with DPR 1.25, it's possible to test this out by setting the environment variable QT_SCALE_FACTOR such that the effective DPR is 1.25. e.g. on my DPR 2.0 display, I set QT_SCALE_FACTOR=0.625

The artifacts are not present in Qt 5.15, Qt 6.2.
The artifacts are present in Qt 6.4 onwards.
(6.3 was not tested)

@pijyoi pijyoi marked this pull request as ready for review November 2, 2023 15:00
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 2, 2023

Thanks @pijyoi for the PR, this LGTM merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants