The method of realizing font size adaptive resolution with pyqt5


Recently, we have encountered a phenomenon that running a good software on a higher resolution computer will lead to incomplete font display and occlusion by controls. Specific reasons can be inquired online, and solutions will be recorded here.

Two methods are recorded here. If the QT version used is later than 5.6.0, it can support high UU DPI, and the application can set this property; if not, it can set the adaptive font for the application.

if __name__ == "__main__":
  v_compare = QVersionNumber(5,6,0)
  V? Current,? = qversionnumber.fromstring (QT? Version? STR)
  if,v_compare) >=0 :
    Qapplication.setattribute (QT. AA? Enablehigh piscaling)? QT starts from 5.6.0 and supports high DPI
    app = QApplication(sys.argv)  #
    app = QApplication(sys.argv)
    Font = qfont ("Tahoma")
    pointsize = font.pointSize()
  mymainwin = Mymainwindow()

Be careful:The qapplication.setattribute (QT. AA? Enablehighdpiscaling) is before the QApplication project is created.

The way to realize the font size adaptive resolution in pyqt5 above is all the content shared by Xiaobian. I hope it can give you a reference, and I hope you can support developepaer more.