get the numeric RGB color values ( QColor)
-
Using QColor selection, I would like to know how to get and store the individual R, G, B values as 0-255.
In my example below, I'm just focusing on trying to get one value to work so I understand the concept, but the output is not as I'd expect.-
When I pick pure red from the color selector, my debug code is showing the output of MyRed as: Color Choosen : "ÿ"
-
What I want and thought would display based on the help file is: Color Choosen : "255"
-
Then, what I ultimately need to get to is something like pure red yields MyRed = 255 , MyGreen = 0, MyBlue = 0
void MainWindow::on_pushButton_clicked() { QString MyRed; QColor color = QColorDialog::getColor(Qt::yellow, this ).rgb(); if( color.isValid() ) { //qDebug() << "Color Choosen : " << color.name(); MyRed = color.red(); qDebug() << "Color Choosen : " << MyRed; } };
-
-
@Craiginator said in get the numeric RGB color values ( QColor):
MyRed = color.red();
You're assigning an integer to a QString - what do you expect??
You're looking either for QString::number() or simplyqDebug() << "Color Choosen : " << color.red();
or even
qDebug() << "Color Choosen : " << color.name(QColor::HexArgb);
-
Holy Cow , that was silly. I waisted more time than I'd like to say and all over 1 mistake I kept overlooking.
Thanks! -
@Christian-Ehrlicher said in get the numeric RGB color values ( QColor):
You're assigning an integer to a QString - what do you expect??
You're looking either for QString::number() or simplyand one of the huge dangers of overloaded constructors run amuck.