Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Python Qt6 - change font size at runtime
Forum Updated to NodeBB v4.3 + New Features

Python Qt6 - change font size at runtime

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 1 Posters 263 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.
  • P Offline
    P Offline
    PythonQTMarlem
    wrote on 10 Oct 2023, 20:33 last edited by
    #1

    Re: Python Qt6 - change font size at runtime

    This Code works:

    if __name__ == '__main__':
        app = QApplication(sys.argv)
        window = HTMLGeneratorApp()
        window.setStyleSheet('font-size: 30px')
        window.show()
        app.setStyleSheet(
            """     QPushButton:focus { background-color: yellow }      QTextEdit:focus { background-color: yellow }     """)
    
        sys.exit(app.exec())
    
    

    The Software changes the font-size.

    This code doesn't work:

        def change_font_size(self, new_font_size):
            # Aktualisieren Sie die Schriftgröße für das Hauptfenster
            self.setStyleSheet(f'font-size: {new_font_size}px;')
            print(f"Ändere Schriftgröße auf: {new_font_size}")
    
    

    The Software doesn't change the font-size.

    what is wrong?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      PythonQTMarlem
      wrote on 11 Oct 2023, 07:29 last edited by
      #2

      I figured it out:

      def change_font_size(self, new_font_size):
              """
              Ändert die Schriftgröße im QMainWindow
              """
      
              fontsize = new_font_size
              self.setStyleSheet('font-size: ' + fontsize+'px')
      
      
      1 Reply Last reply
      0

      1/2

      10 Oct 2023, 20:33

      • Login

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