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. Changing the css of QLineEdit
Forum Updated to NodeBB v4.3 + New Features

Changing the css of QLineEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.9k Views 1 Watching
  • 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.
  • W Offline
    W Offline
    WhatIf
    wrote on last edited by WhatIf
    #1

    Hi,

    I'm trying to update info in a lineedit but I want the modified info to display in red. When it's modified (even if the same exact info is retyped), I want it to display in red.

    What I did is :

    1. Using Qt designer I have the info inside the lineedit display in green.
    2. retrieve info and load it in lineedit
    3. after info is loaded, I try to change future text by ui->updateNameLEdit->setStyleSheet("color: red");

    the lineedit info display in geen. When I attempt to modify, it remains in green. How can I get it to work?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      This wiki article might be of interest.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • W Offline
        W Offline
        WhatIf
        wrote on last edited by
        #3

        I followed the instructions to the best of my ability but it doesn't seem to be work still.

            ui->updateNameLEdit->setStyleSheet("QLineEdit[urgent=true] { color: red;}");
            ui->updateNameLEdit->setProperty("urgent", true);
            ui->updateNameLEdit->style()->unpolish(ui->updateNameLEdit);
            ui->updateNameLEdit->style()->polish(ui->updateNameLEdit);
        
        raven-worxR 1 Reply Last reply
        0
        • W WhatIf

          I followed the instructions to the best of my ability but it doesn't seem to be work still.

              ui->updateNameLEdit->setStyleSheet("QLineEdit[urgent=true] { color: red;}");
              ui->updateNameLEdit->setProperty("urgent", true);
              ui->updateNameLEdit->style()->unpolish(ui->updateNameLEdit);
              ui->updateNameLEdit->style()->polish(ui->updateNameLEdit);
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @WhatIf

          ui->updateNameLEdit->setStyleSheet("QLineEdit { color: red;}");
          

          If you set the stylesheet directly this way, it definitly works. No need to do the polishing again.
          If it still doesnt work you need to show your code, because you might change something in another place?

          --- 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

          1 Reply Last reply
          0
          • W Offline
            W Offline
            WhatIf
            wrote on last edited by
            #5

            My mistake...had the code in the wrong place. But I'm not getting the output I'm after.

            If I only include

                ui->updateNameLEdit->setStyleSheet("QLineEdit[urgent=true] { color: red;}");
                
            

            the text from the start display in black.

            if I include the four lines of code

                ui->updateNameLEdit->setStyleSheet("QLineEdit[urgent=true] { color: red;}");
                ui->updateNameLEdit->setProperty("urgent", true);
                ui->updateNameLEdit->style()->unpolish(ui->updateNameLEdit);
                ui->updateNameLEdit->style()->polish(ui->updateNameLEdit);
            

            the text display in red from start.

            What I was looking for is for the text to display first in green and if it's changed, the text should display in red.

            raven-worxR 1 Reply Last reply
            0
            • W WhatIf

              My mistake...had the code in the wrong place. But I'm not getting the output I'm after.

              If I only include

                  ui->updateNameLEdit->setStyleSheet("QLineEdit[urgent=true] { color: red;}");
                  
              

              the text from the start display in black.

              if I include the four lines of code

                  ui->updateNameLEdit->setStyleSheet("QLineEdit[urgent=true] { color: red;}");
                  ui->updateNameLEdit->setProperty("urgent", true);
                  ui->updateNameLEdit->style()->unpolish(ui->updateNameLEdit);
                  ui->updateNameLEdit->style()->polish(ui->updateNameLEdit);
              

              the text display in red from start.

              What I was looking for is for the text to display first in green and if it's changed, the text should display in red.

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

              @WhatIf said:

              ui->updateNameLEdit->setProperty("urgent", false);
              ui->updateNameLEdit->setStyleSheet(
                    "QLineEdit { color: green; }"
                    "QLineEdit[urgent=true] { color: red;}"
              );
              connect( ui->updateNameLEdit, SIGNAL(textChanged(const QSTring &)), this, SLOT(onTextChanged()),  )
              ...
              void onTextChanged()
              {
                   ui->updateNameLEdit->setProperty("urgent", true);
                   ui->updateNameLEdit->style()->polish( ui->updateNameLEdit );
              }
              

              this should be all you need to achieve this

              --- 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

              1 Reply Last reply
              2

              • Login

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