Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-37851

QVariant loses alpha value when converting QColor to QString

    XMLWordPrintable

Details

    Description

      Here's some code to reproduce:

          QColor color("#88112233");
          QJsonValue jsonValue = QJsonValue::fromVariant(color);
      
          qDebug() << color;
          qDebug() << color.name();
          qDebug() << QVariant(color);
          qDebug() << QVariant(color).toString();
          qDebug() << jsonValue;
       
      

      // Debug output from above code

      // QColor(ARGB 0.533333, 0.0666667, 0.133333, 0.2)
      // "#112233"
      // QVariant(QColor, QColor(ARGB 0.533333, 0.0666667, 0.133333, 0.2) )
      // "#112233"
      // QJsonValue(string, "#112233") <-- alpha value is missing

      // It seems you have to do something manually like convert to rgba qint32 first...

      QColor color;
      QVariant v(color.rgba());

      //Retrieve
      QColor color = QColor::fromRgba(v.toUInt());

      ... but that isn't sufficient if you want to read QColor as a variant into a QJsonValue using QJsonValue::fromVariant()

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              laknoll Lars Knoll
              miketrahearn Mike Trahearn
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes