Converting QColor into QString without losing alpha value

5.6k views Asked by At

Consider the code:

QColor m_color = QColor(255,255,255,0); //alpha is 0
QString m_str = m_color.name(); //#ffffff

m_color is a transparent color with alpha value 0. Now I want to convert this color value into QString without losing transparency (alpha value).

QColor.name() converts it to #ffffff which is 'white' color whereas I want transparent color. What should I do?

1

There are 1 answers

0
Felix On BEST ANSWER

Simple answer: Just use the second overload of QColor::name:

QString m_str = m_color.name(QColor::HexArgb); //#00ffffff

Note: Please check the Qt documentation first for such questions - it is barely worth asking on STOF...