+static QColor stringToColor(QString strColor)
+{
+ bool ok = false;
+ QColor color("black");
+ int intval = 0;
+ if (strColor.startsWith("0x")) {
+ if (strColor.length() == 10) {
+ // 0xRRGGBBAA
+ intval = strColor.toUInt(&ok, 16);
+ color.setRgb( ( intval >> 24 ) & 0xff, // r
+ ( intval >> 16 ) & 0xff, // g
+ ( intval >> 8 ) & 0xff, // b
+ ( intval ) & 0xff ); // a
+ } else {
+ // 0xRRGGBB, 0xRGB
+ color.setNamedColor(strColor.replace(0, 2, "#"));
+ }
+ } else {
+ if (strColor.length() == 9) {
+ // #AARRGGBB
+ strColor = strColor.replace('#', "0x");
+ intval = strColor.toUInt(&ok, 16);
+ color.setRgb( ( intval >> 16 ) & 0xff, // r
+ ( intval >> 8 ) & 0xff, // g
+ ( intval ) & 0xff, // b
+ ( intval >> 24 ) & 0xff ); // a
+ } else if (strColor.length() == 8) {
+ // 0xRRGGBB
+ strColor = strColor.replace('#', "0x");
+ color.setNamedColor(strColor);
+ } else {
+ // #RRGGBB, #RGB
+ color.setNamedColor(strColor);
+ }
+ }
+
+ return color;
+}