The method of realizing font size adaptive resolution with pyqt5

Time:2019-12-10

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 QVersionNumber.compare(v_current,v_compare) >=0 :
    Qapplication.setattribute (QT. AA? Enablehigh piscaling)? QT starts from 5.6.0 and supports high DPI
    app = QApplication(sys.argv)  #
  else:
    app = QApplication(sys.argv)
    Font = qfont ("Tahoma")
    pointsize = font.pointSize()
    font.setPixelSize(pointsize*90/72)
    app.setFont(font)
  mymainwin = Mymainwindow()
  mymainwin.show()
  sys.exit(app.exec())

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.

Recommended Today

Docker learning (5) basic command of dockerfile

To learn dockerfile, you need to understand its basic commands From – base image Try to use the official reference image [x] From Tomcat: 8.5.50-jdk8-openjdk 񖓿 make reference image (based on Tomcat: 8.5.50-jdk8-openjdk) [x] From CentOS ා make a base image based on CentOS: latest [x] From scratch? Does not depend on any reference image […]