Fix windows hidpi (#1516)

* 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

* Fix pg not defined
This commit is contained in:
Ogi Moore 2021-01-27 10:59:07 -08:00 committed by GitHub
parent 85773e4530
commit 309195ceea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
65 changed files with 140 additions and 73 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). 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 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 #. If PyQt5 is already imported, use that
#. Else, if PySide2 is already imported, use that #. Else, if PySide2 is already imported, use that
#. Else, attempt to import PyQt5 #. Else, if PySide6 is already imported, use that
#. If that import fails, attempt to import PySide2. #. 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 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:: make sure it is imported before pyqtgraph::

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg import pyqtgraph as pg
import pyqtgraph.opengl as gl import pyqtgraph.opengl as gl
app = QtGui.QApplication([]) app = pg.mkQApp("GLMeshItem Example")
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GLMeshItem') 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) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl import pyqtgraph.opengl as gl
import numpy as np import numpy as np
app = QtGui.QApplication([]) app = pg.mkQApp("GLScatterPlotItem Example")
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.opts['distance'] = 20 w.opts['distance'] = 20
w.show() w.show()

View File

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

View File

@ -6,10 +6,10 @@ Very basic 3D graphics example; create a view widget and add a few items.
## Add path to library (just for examples; you do not need this) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
from pyqtgraph.Qt import QtCore, QtGui from pyqtgraph.Qt import QtCore, QtGui, mkQApp
import pyqtgraph.opengl as gl import pyqtgraph.opengl as gl
app = QtGui.QApplication([]) app = mkQApp("GLViewWidget Example")
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.opts['distance'] = 20 w.opts['distance'] = 20
w.show() 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) ## Add path to library (just for examples; you do not need this)
import initExample import initExample
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl import pyqtgraph.opengl as gl
app = QtGui.QApplication([]) app = pg.mkQApp("GLVolumeItem Example")
w = gl.GLViewWidget() w = gl.GLViewWidget()
w.opts['distance'] = 200 w.opts['distance'] = 200
w.show() w.show()

View File

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

View File

@ -7,7 +7,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg import pyqtgraph as pg
app = QtGui.QApplication([]) app = pg.mkQApp("Gradiant Editor Example")
mw = pg.GraphicsView() mw = pg.GraphicsView()
mw.resize(800,800) mw.resize(800,800)
mw.show() 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 = QtGui.QMainWindow()
w.show() w.show()
w.setWindowTitle('pyqtgraph example: GradientWidget') w.setWindowTitle('pyqtgraph example: GradientWidget')

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,7 +12,7 @@ from pyqtgraph.Qt import QtGui, QtCore
import numpy as np import numpy as np
import pyqtgraph as pg import pyqtgraph as pg
from pyqtgraph.ptime import time from pyqtgraph.ptime import time
app = QtGui.QApplication([]) app = pg.mkQApp("MultiPlot Speed Test")
plot = pg.plot() plot = pg.plot()
plot.setWindowTitle('pyqtgraph example: MultiPlotSpeedTest') 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)") print("MultiPlot is only used with MetaArray for now (and you do not have the metaarray package)")
exit() exit()
app = QtGui.QApplication([]) app = pg.mkQApp("MultiPlot Widget Example")
mw = QtGui.QMainWindow() mw = QtGui.QMainWindow()
mw.resize(800,800) mw.resize(800,800)
pw = MultiPlotWidget() pw = MultiPlotWidget()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import numpy as np import numpy as np
import ast import ast
app = QtGui.QApplication([]) app = pg.mkQApp("SpinBox Example")
spins = [ 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 from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg import pyqtgraph as pg
app = QtGui.QApplication([]) app = pg.mkQApp("Symbols Examples")
win = pg.GraphicsLayoutWidget(show=True, title="Scatter Plot Symbols") win = pg.GraphicsLayoutWidget(show=True, title="Scatter Plot Symbols")
win.resize(1000,600) win.resize(1000,600)

View File

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

View File

@ -10,7 +10,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import numpy as np import numpy as np
app = QtGui.QApplication([]) app = pg.mkQApp("TreeWidget Example")
w = pg.TreeWidget() w = pg.TreeWidget()
w.setColumnCount(2) 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:]) args = parser.parse_args(sys.argv[1:])
#QtGui.QApplication.setGraphicsSystem('raster') #QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([]) app = pg.mkQApp("Video Speed Test Example")
win = QtGui.QMainWindow() win = QtGui.QMainWindow()
win.setWindowTitle('pyqtgraph example: VideoSpeedTest') win.setWindowTitle('pyqtgraph example: VideoSpeedTest')

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui from pyqtgraph.Qt import QtCore, QtGui
app = QtGui.QApplication([]) app = pg.mkQApp("Parameter Tree Example")
import pyqtgraph.parametertree.parameterTypes as pTypes import pyqtgraph.parametertree.parameterTypes as pTypes
from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem, registerParameterType 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 initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui from pyqtgraph.Qt import QtCore, QtGui, mkQApp
import numpy as np import numpy as np
app = QtGui.QApplication([]) app = mkQApp()
# win.setWindowTitle('pyqtgraph example: ____') # win.setWindowTitle('pyqtgraph example: ____')

View File

@ -457,8 +457,8 @@ USE_PYQT4 = QT_LIB == PYQT4
USE_PYQT5 = QT_LIB == PYQT5 USE_PYQT5 = QT_LIB == PYQT5
## Make sure we have Qt >= 4.7 ## Make sure we have Qt >= 5.12
versionReq = [4, 7] versionReq = [5, 12]
m = re.match(r'(\d+)\.(\d+).*', QtVersion) m = re.match(r'(\d+)\.(\d+).*', QtVersion)
if m is not None and list(map(int, m.groups())) < versionReq: if m is not None and list(map(int, m.groups())) < versionReq:
print(list(map(int, m.groups()))) print(list(map(int, m.groups())))
@ -482,7 +482,6 @@ class App(QtGui.QApplication):
color = palette.base().color().name() color = palette.base().color().name()
self.dark_mode = color.lower() != "#ffffff" self.dark_mode = color.lower() != "#ffffff"
QAPP = None QAPP = None
def mkQApp(name=None): def mkQApp(name=None):
""" """
@ -494,8 +493,20 @@ def mkQApp(name=None):
============== ======================================================== ============== ========================================================
""" """
global QAPP global QAPP
QAPP = QtGui.QApplication.instance() QAPP = QtGui.QApplication.instance()
if QAPP is None: 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"]) QAPP = App(sys.argv or ["pyqtgraph"])
if name is not None: if name is not None:

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ except ImportError:
import pickle import pickle
from .remoteproxy import RemoteEventHandler, ClosedError, NoResultError, LocalObjectProxy, ObjectProxy from .remoteproxy import RemoteEventHandler, ClosedError, NoResultError, LocalObjectProxy, ObjectProxy
from ..Qt import QT_LIB from ..Qt import QT_LIB, mkQApp
from ..util import cprint # color printing for debugging from ..util import cprint # color printing for debugging
@ -451,7 +451,7 @@ def startQtEventLoop(name, port, authkey, ppid, debug=False):
app = QtGui.QApplication.instance() app = QtGui.QApplication.instance()
#print app #print app
if app is None: if app is None:
app = QtGui.QApplication([]) app = mkQApp()
app.setQuitOnLastWindowClosed(False) ## generally we want the event loop to stay open app.setQuitOnLastWindowClosed(False) ## generally we want the event loop to stay open
## until it is explicitly closed by the parent process. ## until it is explicitly closed by the parent process.

View File

@ -56,9 +56,41 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
self.keysPressed = {} self.keysPressed = {}
self.keyTimer = QtCore.QTimer() self.keyTimer = QtCore.QTimer()
self.keyTimer.timeout.connect(self.evalKeyState) self.keyTimer.timeout.connect(self.evalKeyState)
self.makeCurrent() 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): def reset(self):
""" """
Initialize the widget state or reset the current state to the original state. Initialize the widget state or reset the current state to the original state.