Moving window to another screen will disable font size changing function
-
The development environment is PyQt5 with Python 3.8, on Windows 10.
I'm using two monitors in different resolution, one of them is 1920x1080, another is 1600x900.
I've added a font size changing function and it works well. But when I move the window to another screen, font size changing function doesn't work any more. The method does be called because the font size message still shows on status bar.When there are two screens, you can move the window to the center of them and when half of the window is on another screen, the DPI scaling of the entire window will change to adapt that screen, and when this happens, the font size changing function will stop working.
So is it a bug or there is something I have to do to avoid this? Or does it only happens on PyQt5?
I have added an attribute setting line before app, but it doesn't work.
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication(sys.argv)
And follows my font size changing code:
# The button is in menu bar self.action_font_plus.triggered.connect(self.onFontPlusTrig) self.action_font_minus.triggered.connect(self.onFontMinusTrig) # ... def onFontPlusTrig(self): size = self.fontSize.pointSize() + 1 if size > 35: self.statusBar().showMessage("字体不能再大了") else: self.statusBar().showMessage(f"当前字体大小为 {size}pt") self.dataSeg.setFontSize(size) self.fontSize.setPointSize(size) self.setFont(self.fontSize) def onFontMinusTrig(self): size = self.fontSize.pointSize() - 1 if size < 5: self.statusBar().showMessage("字体不能再小了") else: self.statusBar().showMessage(f"当前字体大小为 {size}pt") self.dataSeg.setFontSize(size) self.fontSize.setPointSize(size) self.setFont(self.fontSize)