Convert QColor and QSize from and to QString
-
Probably it's an easy thing, but I searched a lot (Google, Qt forum, stackoverflow...) and didn't find the answer.
So my problem is: I have QColor and QSize variables I have to convert to QString, and then later back to the related type (QColor or QSize).
I tried a lot of different approaches but no luck so far.
Thanks for your time.
-
you could use the serialization of these objects, if you want to store as a osrt of backup.
For "QColor":http://doc.qt.nokia.com/4.7/qcolor.html#operator-lt-lt-201 and "QSize":http://doc.qt.nokia.com/4.7/qsize.html#operator-gt-gt-99 -
I have to have them in presentable text (QString) format.
-
Hello.
QColor to QString (method QString QColor::name)
http://doc.qt.nokia.com/latest/qcolor.html#name
QString to QColor: you should used constructor QColor(QString &name);I don't now how to directly convert from QSize to QString. But I suggest you get int value height and width and convert them to QString.
(method QString::setNum(int)) -
The QColor to QString and vice versa version is great, thanks, but I would prefer a more unified solution. If I qDebug a QVariant holding QSize or QColor it can print it like
QVariant(QColor, QColor(ARGB 1, 0.784314, 0.392157, 0.392157) )
I would like to do something similar, but I have to convert the value back as well.
[quote author="Ruu_Rinki" date="1319465978"]Hello.
QColor to QString (method QString QColor::name)
http://doc.qt.nokia.com/latest/qcolor.html#name
QString to QColor: you should used constructor QColor(QString &name);I don't now how to directly convert from QSize to QString. But I suggest you get int value height and width and convert them to QString.
(method QString::setNum(int))[/quote] -
There are no built in methods for QColor for doing that. You'll have to write your own. You might want to take the implementation for the [[Doc:QDataStream]] support as a start.