How to get viewport DPI in Python?

   440   0   1
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
I need to know the DPI of the monitor where the current viewport is displayed.

Currently I'm using this snippet to know the DPI of each screen in the system, but I don't know how to tell which one is hosting the viewport.

from PySide2.QtWidgets import QApplication

app = QApplication.instance()
screens = app.screens()

for s in screens:
    dpi = s.physicalDotsPerInch()
    print(dpi)
Edited by Andr - Oct. 1, 2023 10:40:27
  • Quick Links