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. how to change the background color of QLineEdit
QtWS25 Last Chance

how to change the background color of QLineEdit

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 4 Posters 18.8k 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    I am QLineEdit as disabled , I want to change the background color QLineEdit as a grey

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Try this :

      QPalette *palette = new QPalette();
      palette->setColor(QPalette::Base,Qt::gray);
      ui->lineEdit->setPalette(*palette);
      

      Out of curiosity if our QLineEdit is disabled it should have the look and feel of your OS (in my case = grey) to reflect that. Why would you want to change that?

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        Is t possible to make the boundary of QLineEdit of same color that of background trying to make boundary of QLineEdit as invisible

        J.HilkJ 1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          Yes that is possible.

          What have you tried already? How is your background set? Please give us some code, preferable a minimal working example so that we can see the context of what you want.

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            Qt Enthusiast
            wrote on last edited by
            #5

            int Count = 100;
            QPalette* palette = new IN_CURRENT_POOL QPalette();
            palette->setColor(QPalette::Base,QColor(236,236,236));

            QLabel* countLabel = new IN_CURRENT_POOL QLabel(tr("Pin count:"));
            /QLineEdit* lineEdit = new IN_CURRENT_POOL QLineEdit;
            lineEdit->setPalette(*palette);
            lineEdit->setText(QString("%1").arg(pinCount));
            lineEdit->setReadOnly(true);
            countLabel->setBuddy(lineEdit);

            Please let me know how to do the same

            1 Reply Last reply
            0
            • Q Qt Enthusiast

              Is t possible to make the boundary of QLineEdit of same color that of background trying to make boundary of QLineEdit as invisible

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Qt-Enthusiast take a look at qt's StyleSheets

              that should have everything that you need, according to what you described so far.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              1
              • Q Offline
                Q Offline
                Qt Enthusiast
                wrote on last edited by
                #7

                but I am seeing boundary which I do not want I want QLineEdit should be part background widger

                EddyE jsulmJ 2 Replies Last reply
                0
                • Q Qt Enthusiast

                  but I am seeing boundary which I do not want I want QLineEdit should be part background widger

                  EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by Eddy
                  #8

                  @Qt-Enthusiast
                  As I see the context of what you want to do I would advise to use a QLabel instead of the QLineEdit. You never want to use it as an input field are you?

                  If you use QLabel you already have the background color without the border

                  Qt Certified Specialist
                  www.edalsolutions.be

                  EddyE Q 2 Replies Last reply
                  1
                  • Q Offline
                    Q Offline
                    Qt Enthusiast
                    wrote on last edited by
                    #9

                    But I am not able to use copy and paste with

                    https://forum.qt.io/topic/80070/how-to-change-the-mouse-cursor-that-shows-qlable-is-selectable/11

                    1 Reply Last reply
                    0
                    • Q Qt Enthusiast

                      but I am seeing boundary which I do not want I want QLineEdit should be part background widger

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Qt-Enthusiast Did you check the link @J-Hilk provided? It show how to change border of QLineEdit.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • Q Offline
                        Q Offline
                        Qt Enthusiast
                        wrote on last edited by
                        #11

                        I will try

                        1 Reply Last reply
                        0
                        • EddyE Eddy

                          @Qt-Enthusiast
                          As I see the context of what you want to do I would advise to use a QLabel instead of the QLineEdit. You never want to use it as an input field are you?

                          If you use QLabel you already have the background color without the border

                          EddyE Offline
                          EddyE Offline
                          Eddy
                          wrote on last edited by
                          #12

                          @Eddy said in how to change the background color of QLineEdit:

                          As I see the context of what you want to do I would advise to use a QLabel instead of the QLineEdit. You never want to use it as an input field are you?

                          @Qt-Enthusiast Could you please answer the question?

                          Qt Certified Specialist
                          www.edalsolutions.be

                          1 Reply Last reply
                          0
                          • EddyE Eddy

                            @Qt-Enthusiast
                            As I see the context of what you want to do I would advise to use a QLabel instead of the QLineEdit. You never want to use it as an input field are you?

                            If you use QLabel you already have the background color without the border

                            Q Offline
                            Q Offline
                            Qt Enthusiast
                            wrote on last edited by
                            #13

                            @Eddy But I am not able to use copy and paste with

                            https://forum.qt.io/topic/80070/how-to-change-the-mouse-cursor-that-shows-qlable-is-selectable/11

                            reply

                            EddyE 1 Reply Last reply
                            0
                            • Q Qt Enthusiast

                              @Eddy But I am not able to use copy and paste with

                              https://forum.qt.io/topic/80070/how-to-change-the-mouse-cursor-that-shows-qlable-is-selectable/11

                              reply

                              EddyE Offline
                              EddyE Offline
                              Eddy
                              wrote on last edited by
                              #14

                              @Qt-Enthusiast

                              OK, you don't want QLabel because you need copy paste funcitonality. Now I understand.

                              You can use the following stylesheet on your lineedit :

                              ui->lineEdit->setStyleSheet("background: transparent;  border: 0px ;");
                              

                              Qt Certified Specialist
                              www.edalsolutions.be

                              Q 1 Reply Last reply
                              0
                              • Q Offline
                                Q Offline
                                Qt Enthusiast
                                wrote on last edited by
                                #15

                                ui->lineEdit->setStyleSheet("background: transparent; border: 0px ;"); is giving me white color for background , how to set Color with RGB QColor(236,236,236) in below line

                                ui->lineEdit->setStyleSheet("background: transparent; border: 0px ;");

                                1 Reply Last reply
                                0
                                • EddyE Offline
                                  EddyE Offline
                                  Eddy
                                  wrote on last edited by
                                  #16

                                  ui->lineEdit->setStyleSheet("background-color: rgb(236, 236, 236); border: 0px ;");

                                  Qt Certified Specialist
                                  www.edalsolutions.be

                                  1 Reply Last reply
                                  0
                                  • EddyE Eddy

                                    @Qt-Enthusiast

                                    OK, you don't want QLabel because you need copy paste funcitonality. Now I understand.

                                    You can use the following stylesheet on your lineedit :

                                    ui->lineEdit->setStyleSheet("background: transparent;  border: 0px ;");
                                    
                                    Q Offline
                                    Q Offline
                                    Qt Enthusiast
                                    wrote on last edited by Eddy
                                    #17
                                    This post is deleted!
                                    1 Reply Last reply
                                    0
                                    • EddyE Offline
                                      EddyE Offline
                                      Eddy
                                      wrote on last edited by Eddy
                                      #18

                                      @Qt-Enthusiast
                                      Glad you could make it work. Can you please mark this topic as solved and start a new one since this is a totally different question.
                                      Please provide us with the needed code of what you have already and explain as good as possible what you want to do.

                                      Edit : made a new topic for your question : copy from qlineedit using pop up menu

                                      Qt Certified Specialist
                                      www.edalsolutions.be

                                      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