0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Qtでディスプレイの拡大・縮小のスケールを取得する

Posted at

ノートパソコンによってはスケールが200%とかなので、文字の大きさなどでレイアウトが崩れる場合がある。
スケールによらずに表示させるためにスケールを取得したいときは以下の関数を使う。

from qtpy.QtGui import QGuiApplication # qtpyを使っていない場合はPyQt5などからインポートする
def get_scale() -> float:
    screen = QGuiApplication.screens()[0] # メインのスクリーンを取得
    return screen.devicePixelRatio()

ただし、Qt Applicationが走っていないと使えないので注意。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?