Unsolved Convert QString to QColor ( "CR_RED" to QColor(CR_RED))
-
Convert QString to QColor ( "CR_RED" to QColor(CR_RED))
Is there any way we can convert a QString("CR_RED") that I am getting from XML file to color code or rgb string ?
Here is the code:
if(locked.tagName() == "objects")
{
QString colorName = locked.attribute("color","");
QString assetName = locked.firstChild().toText().data();
if(assetName.compare("switch")== 0)
{
for(int i=0;i<m_SwitchList->count();i++)
{
m_SwitchList->at(i)->SetSwitchLockedColor(colorName );
}
}
}Here I need to pass colorName to SetSwitchLockedColor(), but colorName is QString. I need to convert it into QColor or rgb string.
-
hi @ndiwan
you can construct a QColor from QString
https://doc.qt.io/qt-5/qcolor.html#QColor-5 -
Thanks. I used QColor.setNamedColor(QString.toLatin1()). It worked.
-
I am Sorry its not yet working.
I can use QColor::setNamedColor(QString) but it need rgb string. But I have normal QString("CR_RED").Vice-verca is working.
QColor color = CR_RED;
QString rgbString = color.name();Now I can use QColor::setNamedColor(QString) to convert rgbString to QColor.
But i want to convert QString("CR_RED") into QColor/rgb QStringThanks
-
@ndiwan said in Convert QString to QColor ( "CR_RED" to QColor(CR_RED)):
CR_RED
This is not a valid color name for QColor.setNamedColor(). You have to add your own parser for your color names.