summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@digia.com>2014-03-28 14:24:45 +0100
committerLars Knoll <lars.knoll@theqtcompany.com>2015-11-30 12:10:49 +0000
commit2e00500b9f32f25a15563a4fd35375ead12c14a7 (patch)
tree17d9069f5cd546c2d274cd204aefa74c67b84b25 /tests/auto/gui
parent10379e48f154dedb95e2e5bfc17085f8a5183dd2 (diff)
Fix conversion QVariant(QColor) to QString.
QVariant was using QColor::name() to convert a color to string, which by default loses alpha value. The patch is fixing the problem by always including the alpha value in the string when required. [ChangeLog][Core][Variant] QVariant(QColor)::toString() uses QColor::HexArgb format when the alpha component is different from 1. Task-number: QTBUG-37851 Change-Id: I887460c1ea151180ba99d64dd873ba9d6e2268f2 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp10
1 files changed, 10 insertions, 0 deletions
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()