summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/kernel/qguivariant.cpp9
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp10
2 files changed, 16 insertions, 3 deletions
diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp
index ce4a0ec09e..a0769ca671 100644
--- a/src/gui/kernel/qguivariant.cpp
+++ b/src/gui/kernel/qguivariant.cpp
@@ -175,7 +175,8 @@ static bool convert(const QVariant::Private *d, int t,
switch (t) {
case QVariant::ByteArray:
if (d->type == QVariant::Color) {
- *static_cast<QByteArray *>(result) = v_cast<QColor>(d)->name().toLatin1();
+ const QColor *c = v_cast<QColor>(d);
+ *static_cast<QByteArray *>(result) = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb).toLatin1();
return true;
}
break;
@@ -190,9 +191,11 @@ static bool convert(const QVariant::Private *d, int t,
case QVariant::Font:
*str = v_cast<QFont>(d)->toString();
return true;
- case QVariant::Color:
- *str = v_cast<QColor>(d)->name();
+ case QVariant::Color: {
+ const QColor *c = v_cast<QColor>(d);
+ *str = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb);
return true;
+ }
default:
break;
}
diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
index 0e822ced5b..0a704b9f64 100644
--- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
+++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
@@ -250,6 +250,14 @@ void tst_QGuiVariant::toColor_data()
QColor c("red");
QTest::newRow( "string" ) << QVariant( QString( "red" ) ) << c;
QTest::newRow( "solid brush" ) << QVariant( QBrush(c) ) << c;
+ QTest::newRow("qbytearray") << QVariant(QByteArray("red")) << c;
+ QTest::newRow("same color") << QVariant(c) << c;
+ QTest::newRow("qstring(#ff0000)") << QVariant(QString::fromUtf8("#ff0000")) << c;
+ QTest::newRow("qbytearray(#ff0000)") << QVariant(QByteArray("#ff0000")) << c;
+
+ c.setNamedColor("#88112233");
+ QTest::newRow("qstring(#88112233)") << QVariant(QString::fromUtf8("#88112233")) << c;
+ QTest::newRow("qbytearray(#88112233)") << QVariant(QByteArray("#88112233")) << c;
}
void tst_QGuiVariant::toColor()
@@ -260,6 +268,8 @@ void tst_QGuiVariant::toColor()
QVERIFY( value.canConvert( QVariant::Color ) );
QColor d = qvariant_cast<QColor>(value);
QCOMPARE( d, result );
+ QVERIFY(value.convert(QMetaType::QColor));
+ QCOMPARE(d, QColor(value.toString()));
}
void tst_QGuiVariant::toPixmap_data()