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. Palette colors of QLineEdit widget disappear on inactive window

Palette colors of QLineEdit widget disappear on inactive window

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 992 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.
  • D Offline
    D Offline
    David Jacobson
    wrote on last edited by
    #1

    Hello,

    I am successfully setting the background of a QLineEdit widget for a status indication using:

    ... create brushes for the roles QPalette.WindowText, QPalette.Window and then...
    widget.setPalette(palette)

    My problem is that when the user clicks outside of the main app window (makes the app the inactive window), the colors for the QLineEdit widget reverts back to its original color palette. When the window is click on (made the active window), the updated color palette reappears on the QLineEdit widget.

    Is this behavior because widget.setAutoFillBackground(True) ?

    What am I missing here?

    Thank you for any insight and advice.

    raven-worxR 1 Reply Last reply
    0
    • D David Jacobson

      @raven-worx

      Thanks for the tip! Below is my method for setting the brush. I thought it was the basic way of doing it, but, I will look into using the QPalette::ColorGroup.

      palette = QPalette()
      
      brush = QBrush(QColor(pR, pG, pB))
      brush.setStyle(Qt.SolidPattern)
      palette.setBrush(QPalette.Active, QPalette.Window, brush)
      
      pWidget.setPalette(palette)
      
      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #4

      Hi
      I think it goes back to normal looking when it looses focus as u only set
      QPalette.Active
      and docs says
      The color groups:
      The Active group is used for the window that has keyboard focus.
      The Inactive group is used for other windows.

      so i think u need to set for inactive too to keep look when user click outside.
      (and keyboard focus goes else where)

      D 1 Reply Last reply
      3
      • D David Jacobson

        Hello,

        I am successfully setting the background of a QLineEdit widget for a status indication using:

        ... create brushes for the roles QPalette.WindowText, QPalette.Window and then...
        widget.setPalette(palette)

        My problem is that when the user clicks outside of the main app window (makes the app the inactive window), the colors for the QLineEdit widget reverts back to its original color palette. When the window is click on (made the active window), the updated color palette reappears on the QLineEdit widget.

        Is this behavior because widget.setAutoFillBackground(True) ?

        What am I missing here?

        Thank you for any insight and advice.

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #2

        @David-Jacobson
        how do you exactly set the brushes to the palette?
        Note the QPalette::ColorGroup parameter in the setBrush() method!

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        D 1 Reply Last reply
        1
        • raven-worxR raven-worx

          @David-Jacobson
          how do you exactly set the brushes to the palette?
          Note the QPalette::ColorGroup parameter in the setBrush() method!

          D Offline
          D Offline
          David Jacobson
          wrote on last edited by
          #3

          @raven-worx

          Thanks for the tip! Below is my method for setting the brush. I thought it was the basic way of doing it, but, I will look into using the QPalette::ColorGroup.

          palette = QPalette()
          
          brush = QBrush(QColor(pR, pG, pB))
          brush.setStyle(Qt.SolidPattern)
          palette.setBrush(QPalette.Active, QPalette.Window, brush)
          
          pWidget.setPalette(palette)
          
          mrjjM 1 Reply Last reply
          0
          • D David Jacobson

            @raven-worx

            Thanks for the tip! Below is my method for setting the brush. I thought it was the basic way of doing it, but, I will look into using the QPalette::ColorGroup.

            palette = QPalette()
            
            brush = QBrush(QColor(pR, pG, pB))
            brush.setStyle(Qt.SolidPattern)
            palette.setBrush(QPalette.Active, QPalette.Window, brush)
            
            pWidget.setPalette(palette)
            
            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #4

            Hi
            I think it goes back to normal looking when it looses focus as u only set
            QPalette.Active
            and docs says
            The color groups:
            The Active group is used for the window that has keyboard focus.
            The Inactive group is used for other windows.

            so i think u need to set for inactive too to keep look when user click outside.
            (and keyboard focus goes else where)

            D 1 Reply Last reply
            3
            • mrjjM mrjj

              Hi
              I think it goes back to normal looking when it looses focus as u only set
              QPalette.Active
              and docs says
              The color groups:
              The Active group is used for the window that has keyboard focus.
              The Inactive group is used for other windows.

              so i think u need to set for inactive too to keep look when user click outside.
              (and keyboard focus goes else where)

              D Offline
              D Offline
              David Jacobson
              wrote on last edited by
              #5

              @raven-worx @mrjj

              And your tips provided my solution. Thank you. I simply added the following setbrush...

              palette.setBrush(QPalette.Inactive, QPalette.Window, brush)

              1 Reply Last reply
              1

              • Login

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