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. pyqt6: Set CSS - I need help
Forum Updated to NodeBB v4.3 + New Features

pyqt6: Set CSS - I need help

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 599 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 13 Oct 2023, 10:34 last edited by
    #1

    Hello,
    I've tried everything imaginable, I don't understand it.

    here is my code:

        def set_style(self, font_size=None, high_contrast=False):
          style = ''
    
          if font_size:
             style = f'font-size: {font_size}px;'
             self.setStyleSheet(style)  # Stattdessen `self.setStyleSheet`
    
         if high_contrast:
               app_css = """QPushButton:focus { background-color: yellow } QTextEdit:focus { background-color: yellow } QComboBox:focus { background-color: yellow } QMainWindow {background-color: black; color: white;}"""
               self.setStyleSheet(style)
    
    

    If the user just wants to change the font size, it works.

    But as soon as I want to change the font size and the background color and font color of the app, the program crashes.

    Ask:
    How does it work?

    J 1 Reply Last reply 13 Oct 2023, 10:46
    0
    • P PythonQTMarlem
      13 Oct 2023, 10:34

      Hello,
      I've tried everything imaginable, I don't understand it.

      here is my code:

          def set_style(self, font_size=None, high_contrast=False):
            style = ''
      
            if font_size:
               style = f'font-size: {font_size}px;'
               self.setStyleSheet(style)  # Stattdessen `self.setStyleSheet`
      
           if high_contrast:
                 app_css = """QPushButton:focus { background-color: yellow } QTextEdit:focus { background-color: yellow } QComboBox:focus { background-color: yellow } QMainWindow {background-color: black; color: white;}"""
                 self.setStyleSheet(style)
      
      

      If the user just wants to change the font size, it works.

      But as soon as I want to change the font size and the background color and font color of the app, the program crashes.

      Ask:
      How does it work?

      J Offline
      J Offline
      JonB
      wrote on 13 Oct 2023, 10:46 last edited by JonB
      #2

      @PythonQTMarlem
      It does not help that you open a new topic for this when you already have one for the same on-going. And there you do not answer questions posed to you. For example, I asked you there what the self is you keep using to set the stylesheet on but you ignored it. If we don't know that it's hard to begin to answer what is going on.

      If your program actually "crashes", run it under debugger and show us the error and the stack trace.

      The code you show does not set all the color stuff since you assign the string to app_css variable and do not use that.

      When you do use it, can you please append a ; each place after yellow. I don't know if it's compulsory there, but if you are having problems why don't you at least eliminate that?

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PythonQTMarlem
        wrote on 13 Oct 2023, 14:19 last edited by
        #3

        Hello,
        At first I thought I had a problem with the menu. Now I've come to the conclusion that it's the CSS. There are no error messages at the moment, but here is debug information as requested:

        app_css = {str} 'QPushButton:focus { background-color: yellow } QTextEdit:focus { background-color: yellow } QComboBox:focus { background-color: yellow } QMainWindow {background-color: black; color: white;}'
        font_size = {str} '30'
        high_contrast = {bool} True
        self = {HTMLGeneratorApp} <main.HTMLGeneratorApp object at 0x0000026E98A09EA0>
        style = {str} 'font-size: 30px;'

        1 Reply Last reply
        0

        1/3

        13 Oct 2023, 10:34

        • Login

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