how to set the background color equal to background color of stylesheets
-
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
-
@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);
-
This code is not working
-
@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);
-
@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!
-
I am getting black color as background color
-
@Qt-Enthusiast
I would understand if you get anunresolved overloaded function type
error.
Because in the example I did not writergb.red()
as I should have butrgb.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()?
-
This post is deleted!
-
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
-
the solution is in your previous post :
// QColor rgb(150,150,150);
but you commented it outDo you understand the concept of RGB color values?
-
@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 -
This post is deleted!
-
@Qt-Enthusiast
We already gave you the solution to that question in another postDid you try it? What is not ok with that solution?
-
no the color mismacthes from background and it is not perfect macth
-
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;");
-
I will try