replace QDesktopWidget() with QGuiApplication.primaryScreen()

the "try, except" could be dropped if we drop Qt4 support.

however, primaryScreen() may not be the right screen.
This commit is contained in:
KIU Shueng Chuan 2021-01-11 18:05:34 +08:00
parent 92016d3d5a
commit 1a6918a241
2 changed files with 10 additions and 2 deletions

View File

@ -45,7 +45,11 @@ class PrintExporter(Exporter):
#res = printer.resolution()
sr = self.getSourceRect()
#res = sr.width() * .4 / (self.params['width'] * 100 / 2.54)
res = QtGui.QDesktopWidget().physicalDpiX()
try:
res = QtGui.QDesktopWidget().physicalDpiX()
except AttributeError:
# This is available since Qt 5
res = QtGui.QGuiApplication.primaryScreen().physicalDotsPerInchX()
printer.setResolution(res)
rect = printer.pageRect()
center = rect.center()

View File

@ -195,7 +195,11 @@ def _generateItemSvg(item, nodes=None, root=None, options={}):
buf = QtCore.QBuffer(arr)
svg = QtSvg.QSvgGenerator()
svg.setOutputDevice(buf)
dpi = QtGui.QDesktopWidget().logicalDpiX()
try:
dpi = QtGui.QDesktopWidget().logicalDpiX()
except AttributeError:
# This is available since Qt 5
dpi = QtGui.QGuiApplication.primaryScreen().logicalDotsPerInchX()
svg.setResolution(dpi)
p = QtGui.QPainter()