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 set the background color equal to background color of stylesheets
Forum Updated to NodeBB v4.3 + New Features

how to set the background color equal to background color of stylesheets

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 5 Posters 14.4k Views 3 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on 13 Jun 2017, 09:28 last edited by
    #1

    class edit : public QLineEdit {
    public:
    edit(QString text);
    }

    edit::edit(QString text) {
    QColor color(QWidget::palette().color(QWidget::backgroundRole()));
    setStyleSheet("background-color: color; border: 0px ;")
    setText(text);

    }

    I am not able to set the color as background color in styleSheet .

    Color::setNamedColor: Unknown color name 'color'

    Could you please review the same

    J 1 Reply Last reply 13 Jun 2017, 09:54
    0
    • Q Qt Enthusiast
      13 Jun 2017, 09:28

      class edit : public QLineEdit {
      public:
      edit(QString text);
      }

      edit::edit(QString text) {
      QColor color(QWidget::palette().color(QWidget::backgroundRole()));
      setStyleSheet("background-color: color; border: 0px ;")
      setText(text);

      }

      I am not able to set the color as background color in styleSheet .

      Color::setNamedColor: Unknown color name 'color'

      Could you please review the same

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 13 Jun 2017, 09:54 last edited by
      #2

      @Qt-Enthusiast
      setStyleSheet is basically expecting a string, and you try to give him a QColor container, that won't work.

      Something like this should work.

      QColor color(QWidget::palette().color(QWidget::backgroundRole()));
      QString style("background-color: rgb(1%,2%,3%); border: 0px ;");
      style.arg(color.red).arg(color.green).arg(color.blue);
      setStyleSheet(style);
      

      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
      2
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on 13 Jun 2017, 10:26 last edited by
        #3

        This code is not working

        J J 2 Replies Last reply 13 Jun 2017, 10:42
        0
        • Q Qt Enthusiast
          13 Jun 2017, 10:26

          This code is not working

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 13 Jun 2017, 10:42 last edited by J.Hilk
          #4

          @Qt-Enthusiast I admit, I made a pretty big typo there, but I would expect you to find that.

          QColor color(QWidget::palette().color(QWidget::backgroundRole()));
          QString style("background-color: rgb(%1,%2,%3); border: 0px ;").arg(color.red).arg(color.green).arg(color.blue);
          setStyleSheet(style);
          

          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
          4
          • Q Qt Enthusiast
            13 Jun 2017, 10:26

            This code is not working

            J Online
            J Online
            jsulm
            Lifetime Qt Champion
            wrote on 13 Jun 2017, 10:45 last edited by
            #5

            @Qt-Enthusiast "This code is not working" - really, you should at least try to find out what is wrong in the code you get here!

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

            1 Reply Last reply
            2
            • Q Offline
              Q Offline
              Qt Enthusiast
              wrote on 13 Jun 2017, 11:11 last edited by
              #6

              I am getting black color as background color

              J 1 Reply Last reply 13 Jun 2017, 11:35
              0
              • Q Qt Enthusiast
                13 Jun 2017, 11:11

                I am getting black color as background color

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 13 Jun 2017, 11:35 last edited by
                #7

                @Qt-Enthusiast
                I would understand if you get an unresolved overloaded function type error.
                Because in the example I did not write rgb.red() as I should have but rgb.red, A clear sign, that I rely to heavily on Qt-Creators auto complete...

                this works, I just tested this in a small example

                QLabel *l = new QLabel();
                    l->resize(50,50);
                    l->show();
                    QColor rgb(QWidget::palette().color(QWidget::backgroundRole()));
                //    QColor rgb(150,150,150);
                    QString style = QString("background-color: rgb(%1,%2,%3); border: 0px ;").arg(rgb.red()).arg(rgb.green()).arg(rgb.blue());
                    l->setStyleSheet(style);
                    connect(this, &Widget::destroyed, l, &QLabel::deleteLater);
                

                What do you get as values, if you print your QColor in e.g. qDebug()?


                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 13 Jun 2017, 14:01 last edited by
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    Qt Enthusiast
                    wrote on 13 Jun 2017, 14:08 last edited by
                    #9

                    My back ground color is wrong

                    color1.red 255 color gree 255 color blue 255 but in actual my background is grey how to get background color as grey

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      Eddy
                      wrote on 13 Jun 2017, 15:46 last edited by
                      #10

                      the solution is in your previous post :
                      // QColor rgb(150,150,150);
                      but you commented it out

                      Do you understand the concept of RGB color values?

                      Qt Certified Specialist
                      www.edalsolutions.be

                      Q 1 Reply Last reply 14 Jun 2017, 03:23
                      2
                      • Q Offline
                        Q Offline
                        Qt Enthusiast
                        wrote on 14 Jun 2017, 03:22 last edited by Qt Enthusiast
                        #11

                        @Eddy I do understand the RGB values concept . but I do not want to set a harcorred color .,I want to keep the color of QLIneEdit same as that of it background , with out harding the RGB values my concern is
                        QColor rgb(QWidget::palette().color(QWidget::backgroundRole())); is not giving me proper background color of the frame ? how to get that

                        1 Reply Last reply
                        0
                        • E Eddy
                          13 Jun 2017, 15:46

                          the solution is in your previous post :
                          // QColor rgb(150,150,150);
                          but you commented it out

                          Do you understand the concept of RGB color values?

                          Q Offline
                          Q Offline
                          Qt Enthusiast
                          wrote on 14 Jun 2017, 03:23 last edited by
                          #12
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • E Offline
                            E Offline
                            Eddy
                            wrote on 14 Jun 2017, 03:43 last edited by
                            #13

                            @Qt-Enthusiast
                            We already gave you the solution to that question in another post

                            Did you try it? What is not ok with that solution?

                            Qt Certified Specialist
                            www.edalsolutions.be

                            1 Reply Last reply
                            1
                            • Q Offline
                              Q Offline
                              Qt Enthusiast
                              wrote on 14 Jun 2017, 05:14 last edited by
                              #14

                              no the color mismacthes from background and it is not perfect macth

                              1 Reply Last reply
                              0
                              • E Offline
                                E Offline
                                Eddy
                                wrote on 14 Jun 2017, 12:29 last edited by Eddy
                                #15

                                Could you show us an image of the actual background with the lineedit in it?
                                What OS are you on?

                                Qt Certified Specialist
                                www.edalsolutions.be

                                1 Reply Last reply
                                0
                                • I Offline
                                  I Offline
                                  Ioseph12
                                  wrote on 15 Jun 2017, 10:10 last edited by Ioseph12
                                  #16

                                  You should do somethig like this

                                  std:string clr = "background-color: rgb(" + std::to_string(color.red()) + "," + std::to_string(color.green()) + "," + std::to_string(color.blue()) + "); border: 0px;";
                                  setStyleSheet(clr.c_str());

                                  Another way:

                                  setStyleSeet("background-color: transparent; border 0px;");

                                  1 Reply Last reply
                                  0
                                  • Q Offline
                                    Q Offline
                                    Qt Enthusiast
                                    wrote on 15 Jun 2017, 16:24 last edited by
                                    #17

                                    I will try

                                    1 Reply Last reply
                                    0

                                    7/17

                                    13 Jun 2017, 11:35

                                    • Login

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