View Full Version : stylesheets with RGB
tommy
12th December 2007, 22:35
Hi,
Normally this is how I use to set the background color of my pushbutton:
colorButton->setStyleSheet("background:red;");
But how do you do it using RGB colors?
This doesn't work:
colorButton->setStyleSheet("background:QColor(200,100,150);");
eric
12th December 2007, 23:14
you do it like this
colorButton->setStyleSheet("background:rgb(200,100,150);");
tommy
12th December 2007, 23:26
But why doesn't it work with variables, like below?
int rand1 = 100 + qrand()%155;
int rand2 = 100 + qrand()%155;
int rand3 = 100 + qrand()%155;
colorButton->setStyleSheet("background:rgb(rand1,rand2,rand3);");
ModeZt
12th December 2007, 23:31
Because "background:rgb(rand1,rand2,rand3);" is a string.. and u have "rand1" as a string, not as a number.
Use
QString("background:rgb(%1,%2,%3);").arg(rand1).arg(rand2).arg(rand3)
pherthyl
13th December 2007, 01:02
Hi,
Normally this is how I use to set the background color of my pushbutton:
colorButton->setStyleSheet("background:red;");
But how do you do it using RGB colors?
This doesn't work:
colorButton->setStyleSheet("background:QColor(200,100,150);");
background: #RRGGBB
also works, where RR, GG, and BB are colour values in hex. ie #FFFFFF being white.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.