have mkQApp configure QApplication such that it handles HIDPI displays on Windows (#1509)

* set environment variables before starting QApp

* fix-422

* Better support of hidpi

* Fix Typo in App-Name

* Remove fontScaleFactor bits

* Add documenation for hidpi displays
This commit is contained in:
Ogi Moore 2021-01-27 10:05:56 -08:00 committed by GitHub
parent 1044a7b6c4
commit 98f6b2f1a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
65 changed files with 138 additions and 71 deletions

View File

@ -54,6 +54,28 @@ For the serious application developer, all of the functionality in pyqtgraph is
See the designer documentation for more information on promoting widgets. The "VideoSpeedTest" and "ScatterPlotSpeedTest" examples both demonstrate the use of .ui files that are compiled to .py modules using pyuic5 or pyside-uic. The "designerExample" example demonstrates dynamically generating python classes from .ui files (no pyuic5 / pyside-uic needed).
HiDPI Displays
--------------
PyQtGraph has a method :func:`mkQApp <pyqtgraph.Qt.mkQApp>` that by default sets what we have tested to be the best combination of options to support hidpi displays, when in combination with non-hidpi secondary displays. For your application, you may have instantiated ``QApplication`` yourself, in which case we advise setting these options *before* runing ``QApplication.exec_()``.
For Qt6 bindings, this functionally "just works" without having to set any attributes.
On Versions of Qt >= 5.14 and < 6; you can get ideal behavior with the following lines::
os.environ["QT_ENABLE_HIDPI_SCALING"] = "1"
QApplication.setHighDpiScaleFactorRoundingPolicy(QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
If you are on Qt >= 5.6 and < 5.14; you can get near ideal behavior with the following lines::
QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
With the later, ideal behavior was not achieved.
.. autofunction:: pyqtgraph.Qt.mkQApp
PyQt and PySide
---------------
@ -63,8 +85,9 @@ pyqtgraph is first imported, it automatically determines which library to use by
#. If PyQt5 is already imported, use that
#. Else, if PySide2 is already imported, use that
#. Else, attempt to import PyQt5
#. If that import fails, attempt to import PySide2.
#. Else, if PySide6 is already imported, use that
#. Else, if PyQt6 is already imported, use that
#. Else, attempt to import PyQt5, PySide2, PySide6, PyQt6, in that order.
If you have both libraries installed on your system and you wish to force pyqtgraph to use one or the other, simply
make sure it is imported before pyqtgraph::

View File

@ -15,7 +15,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("Arrow Example")
w = QtGui.QMainWindow()
cw = pg.GraphicsLayoutWidget()

View File

@ -11,7 +11,7 @@ import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("ColorButton Example")
win = QtGui.QMainWindow()
btn = pg.ColorButton()
win.setCentralWidget(btn)

View File

@ -14,7 +14,7 @@ import numpy as np
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("Data Slicing Example")
## Create window with two ImageView widgets
win = QtGui.QMainWindow()

View File

@ -22,7 +22,7 @@ def some_func2():
return sys.exc_info()[2]
app = QtGui.QApplication([])
app = pg.mkQApp("DataTreeWidget Example")
d = {
'a list': [1,2,3,4,5,6, {'nested1': 'aaaaa', 'nested2': 'bbbbb'}, "seven"],
'a dict': {

View File

@ -12,7 +12,7 @@ import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui
app = QtGui.QApplication([])
app = pg.mkQApp("DateAxisItem Example")
# Create a plot with a date-time axis
w = pg.PlotWidget(axisItems = {'bottom': pg.DateAxisItem()})

View File

@ -12,7 +12,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("DiffTreeWidget Example")
A = {
'a list': [1,2,2,4,5,6, {'nested1': 'aaaa', 'nested2': 'bbbbb'}, "seven"],
'a dict': {

View File

@ -12,7 +12,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("Draw Example")
## Create window with GraphicsView widget
w = pg.GraphicsView()

View File

@ -19,7 +19,7 @@ import pyqtgraph as pg
import numpy as np
import pyqtgraph.metaarray as metaarray
app = QtGui.QApplication([])
app = pg.mkQApp("Flowchart Example")
## Create main window with grid layout
win = QtGui.QMainWindow()

View File

@ -13,7 +13,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("Flowchart Custom Node Example")
## Create main window with a grid layout inside
win = QtGui.QMainWindow()

View File

@ -11,7 +11,7 @@ import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("GLBarGraphItem Example")
w = gl.GLViewWidget()
w.opts['distance'] = 40
w.show()

View File

@ -13,7 +13,7 @@ import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("GLImageItem Example")
w = gl.GLViewWidget()
w.opts['distance'] = 200
w.show()

View File

@ -11,7 +11,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
import pyqtgraph.opengl as gl
app = QtGui.QApplication([])
app = pg.mkQApp("GLIsosurface Example")
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GLIsosurface')

View File

@ -11,7 +11,7 @@ import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("GLLinePlotItem Example")
w = gl.GLViewWidget()
w.opts['distance'] = 40
w.show()

View File

@ -11,7 +11,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
import pyqtgraph.opengl as gl
app = QtGui.QApplication([])
app = pg.mkQApp("GLMeshItem Example")
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GLMeshItem')

View File

@ -7,11 +7,12 @@ Demonstrates use of GLScatterPlotItem with rapidly-updating plots.
## Add path to library (just for examples; you do not need this)
import initExample
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("GLScatterPlotItem Example")
w = gl.GLViewWidget()
w.opts['distance'] = 20
w.show()

View File

@ -13,7 +13,7 @@ import pyqtgraph.opengl as gl
import numpy as np
## Create a GL View widget to display data
app = QtGui.QApplication([])
app = pg.mkQApp("GLSurfacePlot Example")
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GLSurfacePlot')

View File

@ -9,7 +9,7 @@ import initExample
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
app = QtGui.QApplication([])
app = pg.mkQApp("GLViewWidget Example")
w = gl.GLViewWidget()
w.opts['distance'] = 20
w.show()

View File

@ -7,10 +7,11 @@ Demonstrates GLVolumeItem for displaying volumetric data.
## Add path to library (just for examples; you do not need this)
import initExample
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
app = QtGui.QApplication([])
app = pg.mkQApp("GLVolumeItem Example")
w = gl.GLViewWidget()
w.opts['distance'] = 200
w.show()

View File

@ -13,7 +13,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
import pyqtgraph.opengl as gl
app = QtGui.QApplication([])
app = pg.mkQApp("GLShaders Example")
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GL Shaders')

View File

@ -7,7 +7,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("Gradiant Editor Example")
mw = pg.GraphicsView()
mw.resize(800,800)
mw.show()

View File

@ -12,7 +12,7 @@ import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("Gradiant Widget Example")
w = QtGui.QMainWindow()
w.show()
w.setWindowTitle('pyqtgraph example: GradientWidget')

View File

@ -12,7 +12,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("Gradiant Layout Example")
view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(l)

View File

@ -6,7 +6,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
from pyqtgraph.GraphicsScene import GraphicsScene
app = QtGui.QApplication([])
app = pg.mkQApp("GraphicsScene Example")
win = pg.GraphicsView()
win.show()

View File

@ -11,7 +11,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("Histogram Lookup Table Example")
win = QtGui.QMainWindow()
win.resize(800,600)
win.show()

View File

@ -11,7 +11,7 @@ import numpy as np
import pyqtgraph as pg
import pyqtgraph.ptime as ptime
app = QtGui.QApplication([])
app = pg.mkQApp("ImageItem Example")
## Create window with GraphicsView widget
win = pg.GraphicsLayoutWidget()

View File

@ -20,7 +20,7 @@ import pyqtgraph as pg
# Interpret image data as row-major instead of col-major
pg.setConfigOptions(imageAxisOrder='row-major')
app = QtGui.QApplication([])
app = pg.mkQApp("ImageView Example")
## Create window with ImageView widget
win = QtGui.QMainWindow()

View File

@ -9,7 +9,7 @@ import numpy as np
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("InfiniteLine Example")
win = pg.GraphicsLayoutWidget(show=True, title="Plotting items examples")
win.resize(1000,600)

View File

@ -12,7 +12,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("Joystick Button Example")
mw = QtGui.QMainWindow()
mw.resize(300,50)
mw.setWindowTitle('pyqtgraph example: JoystickButton')

View File

@ -10,7 +10,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("Log Plot Example")
win = pg.GraphicsLayoutWidget(show=True, title="Basic plotting examples")
win.resize(1000,600)

View File

@ -12,7 +12,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
from pyqtgraph.ptime import time
app = QtGui.QApplication([])
app = pg.mkQApp("MultiPlot Speed Test")
plot = pg.plot()
plot.setWindowTitle('pyqtgraph example: MultiPlotSpeedTest')

View File

@ -14,7 +14,7 @@ except:
print("MultiPlot is only used with MetaArray for now (and you do not have the metaarray package)")
exit()
app = QtGui.QApplication([])
app = pg.mkQApp("MultiPlot Widget Example")
mw = QtGui.QMainWindow()
mw.resize(800,800)
pw = MultiPlotWidget()

View File

@ -41,7 +41,7 @@ P_loss[P_mech > 1.5e5] = np.NaN
# green - orange - red
Gradients['gor'] = {'ticks': [(0.0, (74, 158, 71)), (0.5, (255, 230, 0)), (1, (191, 79, 76))], 'mode': 'rgb'}
app = QtGui.QApplication([])
app = pg.mkQApp("NonUniform Image Example")
win = QtGui.QMainWindow()
cw = pg.GraphicsLayoutWidget()

View File

@ -11,7 +11,7 @@ import numpy as np
import pyqtgraph as pg
import pyqtgraph.ptime as ptime
app = QtGui.QApplication([])
app = pg.mkQApp("PColorMesh Example")
## Create window with GraphicsView widget
win = pg.GraphicsLayoutWidget()

View File

@ -12,7 +12,7 @@ import numpy as np
import pyqtgraph as pg
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
app = pg.mkQApp("Plot Auto Range Example")
#mw = QtGui.QMainWindow()
#mw.resize(800,800)

View File

@ -12,7 +12,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
from pyqtgraph.ptime import time
app = QtGui.QApplication([])
app = pg.mkQApp("Plot Speed Test")
p = pg.plot()
p.setWindowTitle('pyqtgraph example: PlotSpeedTest')

View File

@ -13,7 +13,7 @@ import numpy as np
import pyqtgraph as pg
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
app = pg.mkQApp("Plotting Example")
#mw = QtGui.QMainWindow()
#mw.resize(800,800)

View File

@ -9,7 +9,7 @@ import time
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
app = QtGui.QApplication([])
app = pg.mkQApp("Progress Dialog Example")
def runStage(i):

View File

@ -32,7 +32,7 @@ arr[8:13, 44:46] = 10
## create GUI
app = QtGui.QApplication([])
app = pg.mkQApp("ROI Examples")
w = pg.GraphicsLayoutWidget(show=True, size=(1000,800), border=True)
w.setWindowTitle('pyqtgraph example: ROI Examples')

View File

@ -11,7 +11,7 @@ import pyqtgraph as pg
pg.setConfigOptions(imageAxisOrder='row-major')
## create GUI
app = QtGui.QApplication([])
app = pg.mkQApp("ROI Types Examples")
w = pg.GraphicsLayoutWidget(show=True, size=(800,800), border=True)
v = w.addViewBox(colspan=2)

View File

@ -14,7 +14,7 @@ import numpy as np
from collections import namedtuple
from itertools import chain
app = QtGui.QApplication([])
app = pg.mkQApp("Scatter Plot Item Example")
mw = QtGui.QMainWindow()
mw.resize(800,800)
view = pg.GraphicsLayoutWidget() ## GraphicsView with GraphicsLayout inserted by default

View File

@ -17,7 +17,7 @@ import numpy as np
import pyqtgraph as pg
from pyqtgraph.ptime import time
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
app = pg.mkQApp("Scatter Plot Speed Test")
#mw = QtGui.QMainWindow()
#mw.resize(800,800)
import importlib

View File

@ -15,7 +15,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import ast
app = QtGui.QApplication([])
app = pg.mkQApp("SpinBox Example")
spins = [

View File

@ -10,7 +10,7 @@ import initExample ## Add path to library (just for examples; you do not need th
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("Symbols Examples")
win = pg.GraphicsLayoutWidget(show=True, title="Scatter Plot Symbols")
win.resize(1000,600)

View File

@ -9,7 +9,7 @@ import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("Table Widget Example")
w = pg.TableWidget()
w.show()

View File

@ -10,7 +10,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("TreeWidget Example")
w = pg.TreeWidget()
w.setColumnCount(2)

View File

@ -38,7 +38,7 @@ parser.add_argument('--size', default='512x512', type=lambda s: tuple([int(x) fo
args = parser.parse_args(sys.argv[1:])
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
app = pg.mkQApp("Video Speed Test Example")
win = QtGui.QMainWindow()
win.setWindowTitle('pyqtgraph example: VideoSpeedTest')

View File

@ -18,7 +18,7 @@ import numpy as np
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("ViewBox Example")
mw = QtGui.QMainWindow()
mw.setWindowTitle('pyqtgraph example: ViewBox')
mw.show()

View File

@ -12,7 +12,7 @@ from pyqtgraph.Qt import QtGui, QtCore
from pyqtgraph.Point import Point
#generate layout
app = QtGui.QApplication([])
app = pg.mkQApp("Crosshair Example")
win = pg.GraphicsLayoutWidget(show=True)
win.setWindowTitle('pyqtgraph example: crosshair')
label = pg.LabelItem(justify='right')

View File

@ -24,7 +24,7 @@ import numpy as np
from pyqtgraph.dockarea import *
app = QtGui.QApplication([])
app = pg.mkQApp("DockArea Example")
win = QtGui.QMainWindow()
area = DockArea()
win.setCentralWidget(area)

View File

@ -9,7 +9,7 @@ import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
app = QtGui.QApplication([])
app = pg.mkQApp("Fractal Example")
# Set up UI widgets
win = pg.QtGui.QWidget()

View File

@ -5,7 +5,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
from pyqtgraph.ptime import time
app = QtGui.QApplication([])
app = pg.mkQApp("Infinite Line Performance")
p = pg.plot()
p.setWindowTitle('pyqtgraph performance: InfiniteLine')

View File

@ -11,7 +11,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("Isocurve Example")
## make pretty looping data
frames = 200

View File

@ -13,7 +13,7 @@ import numpy as np
import pyqtgraph as pg
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
app = pg.mkQApp("Linked Views Example")
#mw = QtGui.QMainWindow()
#mw.resize(800,800)

View File

@ -9,7 +9,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
app = QtGui.QApplication([])
app = pg.mkQApp("Log Axis Example")
w = pg.GraphicsLayoutWidget(show=True)
w.setWindowTitle('pyqtgraph example: logAxis')

View File

@ -40,7 +40,7 @@ print( "process finished")
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
app = pg.QtGui.QApplication([])
app = pg.mkQApp("Multiprocess Example")
print( "\n=================\nStart QtProcess")
import sys

View File

@ -15,7 +15,7 @@ import pyqtgraph as pg
import numpy as np
from pyqtgraph import Point
app = pg.QtGui.QApplication([])
app = pg.mkQApp("Optics Demo")
w = pg.GraphicsLayoutWidget(show=True, border=0.5)
w.resize(1000, 900)

View File

@ -14,7 +14,7 @@ import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
app = QtGui.QApplication([])
app = pg.mkQApp("Parameter Tree Example")
import pyqtgraph.parametertree.parameterTypes as pTypes
from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem, registerParameterType

View File

@ -8,10 +8,10 @@ Description of example
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
from pyqtgraph.Qt import QtCore, QtGui, mkQApp
import numpy as np
app = QtGui.QApplication([])
app = mkQApp()
# win.setWindowTitle('pyqtgraph example: ____')

View File

@ -457,8 +457,8 @@ USE_PYQT4 = QT_LIB == PYQT4
USE_PYQT5 = QT_LIB == PYQT5
## Make sure we have Qt >= 4.7
versionReq = [4, 7]
## Make sure we have Qt >= 5.12
versionReq = [5, 12]
m = re.match(r'(\d+)\.(\d+).*', QtVersion)
if m is not None and list(map(int, m.groups())) < versionReq:
print(list(map(int, m.groups())))
@ -482,7 +482,6 @@ class App(QtGui.QApplication):
color = palette.base().color().name()
self.dark_mode = color.lower() != "#ffffff"
QAPP = None
def mkQApp(name=None):
"""
@ -494,8 +493,20 @@ def mkQApp(name=None):
============== ========================================================
"""
global QAPP
QAPP = QtGui.QApplication.instance()
if QAPP is None:
# hidpi handling
qtVersionCompare = tuple(map(int, QtVersion.split(".")))
if qtVersionCompare > (6, 0):
# Qt6 seems to support hidpi without needing to do anything so continue
pass
elif qtVersionCompare > (5, 14):
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "1"
QtGui.QApplication.setHighDpiScaleFactorRoundingPolicy(QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
else: # qt 5.12 and 5.13
QtGui.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
QtGui.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
QAPP = App(sys.argv or ["pyqtgraph"])
if name is not None:

View File

@ -172,7 +172,7 @@ if __name__ == '__main__':
from . import widgets
import GraphicsView
from .functions import *
app = QtGui.QApplication([])
app = pg.mkQApp()
win = QtGui.QMainWindow()
win.show()
cw = GraphicsView.GraphicsView()

View File

@ -227,7 +227,7 @@ if __name__ == '__main__':
from . import widgets
import GraphicsView
from .functions import *
app = QtGui.QApplication([])
app = pg.mkQApp()
win = QtGui.QMainWindow()
win.show()
cw = GraphicsView.GraphicsView()

View File

@ -269,10 +269,10 @@ class DateAxisItem(AxisItem):
# Size in pixels a specific tick label will take
if self.orientation in ['bottom', 'top']:
def sizeOf(text):
return self.fontMetrics.boundingRect(text).width() + padding*self.fontScaleFactor
return self.fontMetrics.boundingRect(text).width() + padding
else:
def sizeOf(text):
return self.fontMetrics.boundingRect(text).height() + padding*self.fontScaleFactor
return self.fontMetrics.boundingRect(text).height() + padding
# Fallback zoom level: Years/Months
self.zoomLevel = YEAR_MONTH_ZOOM_LEVEL
@ -314,6 +314,5 @@ class DateAxisItem(AxisItem):
self.fontMetrics = p.fontMetrics()
# Get font scale factor by current window resolution
self.fontScaleFactor = p.device().logicalDpiX() / 96
return super(DateAxisItem, self).generateDrawSpecs(p)

View File

@ -451,7 +451,7 @@ def startQtEventLoop(name, port, authkey, ppid, debug=False):
app = QtGui.QApplication.instance()
#print app
if app is None:
app = QtGui.QApplication([])
app = pg.mkQApp()
app.setQuitOnLastWindowClosed(False) ## generally we want the event loop to stay open
## until it is explicitly closed by the parent process.

View File

@ -56,9 +56,41 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
self.keysPressed = {}
self.keyTimer = QtCore.QTimer()
self.keyTimer.timeout.connect(self.evalKeyState)
self.makeCurrent()
@property
def _dpiRatio(self):
return self.devicePixelRatioF() or 1
def _updateScreen(self, screen):
self._updatePixelRatio()
if screen is not None:
screen.physicalDotsPerInchChanged.connect(self._updatePixelRatio)
screen.logicalDotsPerInchChanged.connect(self._updatePixelRatio)
def _updatePixelRatio(self):
event = QtGui.QResizeEvent(self.size(), self.size())
self.resizeEvent(event)
def showEvent(self, event):
window = self.window().windowHandle()
window.screenChanged.connect(self._updateScreen)
self._updateScreen(window.screen())
def width(self):
if self._dpiRatio.is_integer():
return super().width()
else:
return int(super().width() * self._dpiRatio)
def height(self):
if self._dpiRatio.is_integer():
return super().height()
else:
return int(super().height() * self._dpiRatio)
def reset(self):
"""
Initialize the widget state or reset the current state to the original state.