[SOLVED] Reading QColor from an INI file
-
look rgba format of the color conseption
place in your ini such record (just sample)
MarkerColor=4294967040
it's look like 4294967040, for example
also u can use the #FFFFFFFF expression, but remember that it is 16 number base and u must interpret it in program
-
in Assistant
An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.
-
I understand. I was wanting to set it as a QColor entry in the INI file. I wonder if that is even possible
-
why?
really possible.
you can read value as string and then analyze it whith RegExp
-
[quote author="Subst27" date="1421077722"]in Assistant
An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.
[/quote]So the entry in the INI file then would be:
@
MarkerColor= @QRgb(#00000080)
@OR
@
MarkerColor= #00000080
@ -
[quote author="Subst27" date="1421077722"]in Assistant
An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.
[/quote]So the entry in the INI file then would be:
@
MarkerColor= @QRgb(#00000080)
@OR
@
MarkerColor= #00000080
@ -
[quote author="Subst27" date="1421077934"]why?
really possible.
you can read value as string and then analyze it whith RegExp
[/quote]
As string? Didn't consider that. OK. I'll try that
-
MarkerColor= #00000080
It seems the obvious and the apply the toHex()
-
whith the string like QColor(R,G,B)
you can remove QColor and brackets and then whis split(",") take the Red,Green and Blue values of your color
-
[quote author="Subst27" date="1421078199"]MarkerColor= #00000080
It seems the obvious and the apply the toHex()[/quote]
toHex() isn't available in this context.
-
try to remove # sign
it's issuer of syntax
from Assistant
QByteArray QByteArray::toHex() const
Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f.
-
[quote author="Subst27" date="1421078846"]try to remove # sign
it's issuer of syntax
from Assistant
QByteArray QByteArray::toHex() const
Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f.
[/quote]It is unclear what you are trying to illustrate.
Perhaps a trivial example?
-
can you wait some minutes?
-
[quote author="Subst27" date="1421079781"]can you wait some minutes?[/quote]
Of course
-
I found better variant
in INI
[common]
color=#FF0000result
"#FF0000"
16711680
QColor(ARGB 1, 1, 0, 0)look code in next message
-
@QSettings settings(qApp->applicationDirPath()+"/color.ini",QSettings::IniFormat);
QColor color;
settings.beginGroup("common");
QString string=settings.value("color","#0000FF").toString();
qDebug()<<string;
string.remove(0,1);
bool ok;
uint value=string.toUInt(&ok,16);
qDebug()<<value;
color=QColor::fromRgb(value);
qDebug()<<color;@ -
I'd add a bit more checking of the input. Before removing the first character, check if it actually is a # sign. And check if the length of the rest is what you expect (6 characters for a 3x8bit color).
-
[quote author="Andre" date="1421081171"]I'd add a bit more checking of the input. Before removing the first character, check if it actually is a # sign. And check if the length of the rest is what you expect (6 characters for a 3x8bit color).[/quote]
well.
I've just wrote the principal solve -
[quote author="Andre" date="1421081171"]I'd add a bit more checking of the input. Before removing the first character, check if it actually is a # sign. And check if the length of the rest is what you expect (6 characters for a 3x8bit color).[/quote]
Thanks as always @Andre and especially thanks to @Subst27! I will mark this Solved for now but will need to refine it a bit
-
[quote author="Subst27" date="1421081450"]
[quote author="Andre" date="1421081171"]I'd add a bit more checking of the input. Before removing the first character, check if it actually is a # sign. And check if the length of the rest is what you expect (6 characters for a 3x8bit color).[/quote]well.
I've just wrote the principal solve[/quote]Yes, of course. But reading an ini file is essentially user imput, so I think input checking should not be just an afterthought. That's why I mentioned it.