Update/improve qt screen script

pre_viz_calls
Tyler Goodlet 2022-11-17 16:01:09 -05:00
parent 11b254be7a
commit fe4a69b353
1 changed files with 40 additions and 31 deletions

View File

@ -1,22 +1,26 @@
""" """
Resource list for mucking with DPIs on multiple screens: DPI and info helper script for display metrics.
- https://stackoverflow.com/questions/42141354/convert-pixel-size-to-point-size-for-fonts-on-multiple-platforms
- https://stackoverflow.com/questions/25761556/qt5-font-rendering-different-on-various-platforms/25929628#25929628
- https://doc.qt.io/qt-5/highdpi.html
- https://stackoverflow.com/questions/20464814/changing-dpi-scaling-size-of-display-make-qt-applications-font-size-get-rendere
- https://stackoverflow.com/a/20465247
- https://doc.qt.io/archives/qt-4.8/qfontmetrics.html#width
- https://forum.qt.io/topic/54136/how-do-i-get-the-qscreen-my-widget-is-on-qapplication-desktop-screen-returns-a-qwidget-and-qobject_cast-qscreen-returns-null/3
- https://forum.qt.io/topic/43625/point-sizes-are-they-reliable/4
- https://stackoverflow.com/questions/16561879/what-is-the-difference-between-logicaldpix-and-physicaldpix-in-qt
- https://doc.qt.io/qt-5/qguiapplication.html#screenAt
""" """
from pyqtgraph import QtGui # Resource list for mucking with DPIs on multiple screens:
# https://stackoverflow.com/questions/42141354/convert-pixel-size-to-point-size-for-fonts-on-multiple-platforms
# https://stackoverflow.com/questions/25761556/qt5-font-rendering-different-on-various-platforms/25929628#25929628
# https://doc.qt.io/qt-5/highdpi.html
# https://stackoverflow.com/questions/20464814/changing-dpi-scaling-size-of-display-make-qt-applications-font-size-get-rendere
# https://stackoverflow.com/a/20465247
# https://doc.qt.io/archives/qt-4.8/qfontmetrics.html#width
# https://forum.qt.io/topic/54136/how-do-i-get-the-qscreen-my-widget-is-on-qapplication-desktop-screen-returns-a-qwidget-and-qobject_cast-qscreen-returns-null/3
# https://forum.qt.io/topic/43625/point-sizes-are-they-reliable/4
# https://stackoverflow.com/questions/16561879/what-is-the-difference-between-logicaldpix-and-physicaldpix-in-qt
# https://doc.qt.io/qt-5/qguiapplication.html#screenAt
from pyqtgraph import (
QtGui,
QtWidgets,
)
from PyQt5.QtCore import ( from PyQt5.QtCore import (
Qt, QCoreApplication Qt,
QCoreApplication,
) )
# Proper high DPI scaling is available in Qt >= 5.6.0. This attibute # Proper high DPI scaling is available in Qt >= 5.6.0. This attibute
@ -28,9 +32,9 @@ if hasattr(Qt, 'AA_UseHighDpiPixmaps'):
QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
app = QtGui.QApplication([]) app = QtWidgets.QApplication([])
window = QtGui.QMainWindow() window = QtWidgets.QMainWindow()
main_widget = QtGui.QWidget() main_widget = QtWidgets.QWidget()
window.setCentralWidget(main_widget) window.setCentralWidget(main_widget)
window.show() window.show()
@ -46,18 +50,20 @@ size = screen.size()
geo = screen.availableGeometry() geo = screen.availableGeometry()
phydpi = screen.physicalDotsPerInch() phydpi = screen.physicalDotsPerInch()
logdpi = screen.logicalDotsPerInch() logdpi = screen.logicalDotsPerInch()
rr = screen.refreshRate()
print( print(
# f'screen number: {screen_num}\n', # f'screen number: {screen_num}\n',
f'screen name: {name}\n' f'screen: {name}\n'
f'screen size: {size}\n' f' size: {size}\n'
f'screen geometry: {geo}\n\n' f' geometry: {geo}\n'
f'devicePixelRationF(): {pxr}\n' f' logical dpi: {logdpi}\n'
f'physical dpi: {phydpi}\n' f' devicePixelRationF(): {pxr}\n'
f'logical dpi: {logdpi}\n' f' physical dpi: {phydpi}\n'
f' refresh rate: {rr}\n'
) )
print('-'*50) print('-'*50 + '\n')
screen = app.primaryScreen() screen = app.primaryScreen()
@ -66,17 +72,20 @@ size = screen.size()
geo = screen.availableGeometry() geo = screen.availableGeometry()
phydpi = screen.physicalDotsPerInch() phydpi = screen.physicalDotsPerInch()
logdpi = screen.logicalDotsPerInch() logdpi = screen.logicalDotsPerInch()
rr = screen.refreshRate()
print( print(
# f'screen number: {screen_num}\n', # f'screen number: {screen_num}\n',
f'screen name: {name}\n' f'screen: {name}\n'
f'screen size: {size}\n' f' size: {size}\n'
f'screen geometry: {geo}\n\n' f' geometry: {geo}\n'
f'devicePixelRationF(): {pxr}\n' f' logical dpi: {logdpi}\n'
f'physical dpi: {phydpi}\n' f' devicePixelRationF(): {pxr}\n'
f'logical dpi: {logdpi}\n' f' physical dpi: {phydpi}\n'
f' refresh rate: {rr}\n'
) )
print('-'*50 + '\n')
# app-wide font # app-wide font
font = QtGui.QFont("Hack") font = QtGui.QFont("Hack")