2
2

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 for Python OS間のフォントの差異を調整する

Posted at

備忘録かつ添削をお願いしたく。
Widgetの大きさはどのOSでもほぼ同様に再現されるのですが、フォントの大きさがそろわない。DPIの違いと関係あるのだろうと当たりを付けてOS間のフォントの大きさを調整するコードを書いてみました。

from PySide2.QtCore import QOperatingSystemVersion
from PySide2 import QtWidgets,QtGui

    currentOsType = QOperatingSystemVersion.currentType()

    if currentOsType == QOperatingSystemVersion.OSType.MacOS:
        font.setPointSize(20)
        return(font)

    if currentOsType == QOperatingSystemVersion.OSType.Windows:
        font.setPointSize(20/1.33333)
    else:
        print(currentOsType)
        font.setPointSize(20/1.33333)

    return(font)

1.3333は、Mac72dpi, Windows96dpiという数値から出したものです。
自分の使っている環境ではこれでほぼ良しなのでそれ以上は調べていません。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?