Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cortical-iv
Created February 16, 2019 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cortical-iv/e100e0445f28cb0465b5441310fe7b4d to your computer and use it in GitHub Desktop.
Save cortical-iv/e100e0445f28cb0465b5441310fe7b4d to your computer and use it in GitHub Desktop.
Calculate dpi in scale-sensitive way
import sys
def get_dpi(screen_num = 0):
"""Calculate the dpi of a given monitor, sensitive to
scaling factors they have set."""
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
screen = app.screens()[screen_num]
dpi = screen.physicalDotsPerInch()
app.quit()
return dpi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment