Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Moving window to another screen will disable font size changing function
QtWS25 Last Chance

Moving window to another screen will disable font size changing function

Scheduled Pinned Locked Moved Unsolved General and Desktop
pyqt5dpifont size
1 Posts 1 Posters 657 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • frank.xinF Offline
    frank.xinF Offline
    frank.xin
    wrote on last edited by frank.xin
    #1

    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)
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved