0

working on a project in Qt. I have a variable that will be 0-255. 255 needs to be black, 0 needs to be white, and anything in between should be some shade of gray. So I have a square QLabel. I'm trying to set a stylesheet, but I keep getting black no matter what I put in. Here is what my code looks like:

QString color = QString("QLabel {background-color: rgb(%1, %1, %1)}").arg(number); label->setStyleSheet(color); 

No matter what 'number' is it always shows as black. Note that I am using windows 8.

2 Answers 2

1

Nevermind. It looks like 255, 255, 255 is white. I thought that would be black for some reason. Silly me.

Sign up to request clarification or add additional context in comments.

Comments

1

The code below works using both Qt 4.8.5 and 5.1.1 on OS X, Windows 7 and Windows 8 (32 bit builds on Windows). The label background is darkish gray.

#include <QApplication> #include <QLabel> int main(int argc, char *argv[]) { QApplication a(argc, argv); QLabel label("foobar"); int number = 100; const QString style = QString("QLabel {background-color: rgb(%1, %1, %1) }") .arg(number); label.setStyleSheet(style); label.show(); return a.exec(); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.