Merge pull request #1735 from pijyoi/fix_dpr

unify _dpiRatio() and devicePixelRatio()
This commit is contained in:
Ogi Moore 2021-04-22 09:52:09 -07:00 committed by GitHub
commit a9161e0794
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,10 +59,6 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
self.makeCurrent() self.makeCurrent()
@property
def _dpiRatio(self):
return self.devicePixelRatioF() or 1
def _updateScreen(self, screen): def _updateScreen(self, screen):
self._updatePixelRatio() self._updatePixelRatio()
if screen is not None: if screen is not None:
@ -79,16 +75,12 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
self._updateScreen(window.screen()) self._updateScreen(window.screen())
def width(self): def width(self):
if self._dpiRatio.is_integer(): dpr = self.devicePixelRatio()
return super().width() return int(super().width() * dpr)
else:
return int(super().width() * self._dpiRatio)
def height(self): def height(self):
if self._dpiRatio.is_integer(): dpr = self.devicePixelRatio()
return super().height() return int(super().height() * dpr)
else:
return int(super().height() * self._dpiRatio)
def reset(self): def reset(self):
@ -147,10 +139,10 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
def getViewport(self): def getViewport(self):
vp = self.opts['viewport'] vp = self.opts['viewport']
dpr = self.devicePixelRatio()
if vp is None: if vp is None:
return (0, 0, int(self.width() * dpr), int(self.height() * dpr)) return (0, 0, self.width(), self.height())
else: else:
dpr = self.devicePixelRatio()
return tuple([int(x * dpr) for x in vp]) return tuple([int(x * dpr) for x in vp])
def devicePixelRatio(self): def devicePixelRatio(self):
@ -158,7 +150,7 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
if dpr is not None: if dpr is not None:
return dpr return dpr
return QtWidgets.QOpenGLWidget.devicePixelRatio(self) return self.devicePixelRatioF()
def resizeGL(self, w, h): def resizeGL(self, w, h):
pass pass
@ -174,8 +166,7 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
def projectionMatrix(self, region=None): def projectionMatrix(self, region=None):
if region is None: if region is None:
dpr = self.devicePixelRatio() region = (0, 0, self.width(), self.height())
region = (0, 0, self.width() * dpr, self.height() * dpr)
x0, y0, w, h = self.getViewport() x0, y0, w, h = self.getViewport()
dist = self.opts['distance'] dist = self.opts['distance']