how to set the background color equal to background color of stylesheets
-
wrote on 13 Jun 2017, 09:28 last edited by
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
-
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);
-
wrote on 13 Jun 2017, 10:26 last edited by
This code is not working
-
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);
-
This code is not working
@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!
-
wrote on 13 Jun 2017, 11:11 last edited by
I am getting black color as background color
-
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()?
-
wrote on 13 Jun 2017, 14:01 last edited byThis post is deleted!
-
wrote on 13 Jun 2017, 14:08 last edited by
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
-
wrote on 13 Jun 2017, 15:46 last edited by
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?
-
wrote on 14 Jun 2017, 03:22 last edited by Qt Enthusiast
@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 -
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?
wrote on 14 Jun 2017, 03:23 last edited byThis post is deleted! -
wrote on 14 Jun 2017, 03:43 last edited by
@Qt-Enthusiast
We already gave you the solution to that question in another postDid you try it? What is not ok with that solution?
-
wrote on 14 Jun 2017, 05:14 last edited by
no the color mismacthes from background and it is not perfect macth
-
wrote on 14 Jun 2017, 12:29 last edited by Eddy
Could you show us an image of the actual background with the lineedit in it?
What OS are you on? -
wrote on 15 Jun 2017, 10:10 last edited by Ioseph12
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;");
-
wrote on 15 Jun 2017, 16:24 last edited by
I will try
7/17