View Full Version : Font Style

20th September 2006, 07:11
I want to use a method "FontStyle" which is already in .net

In QT, I m using QFont::Style. So is it ok?
and another thing is that if i want to take type name of the variable QFont::Style then waht is the method.

At now i m using.

QFont::Style fontStyle;

QString str;
str = QVariant::fromValue(fontStyle).typeName();

but it gives an error.

20th September 2006, 09:29
QFont::Style is just an enum. QVariant cannot convert enum values to strings. QVariant can only tell the type name of the stored value. You''ll just need to introduce the type to QMetaType so that QVariant is able dig out the type name.

#include <QFont>
#include <QVariant>
#include <QtDebug>

// introduce type "QFont::Style" to QMetaType
// this must be in global namespace

int main(int argc, char *argv[])
QFont::Style style = QFont::StyleNormal;
qDebug() << QVariant::fromValue(style).typeName(); // outputs "QFont::Style", not "QFont::StyleNormal"
return 0;

If you want to get "StyleNormal", "StyleItalic", "StyleOblique".. just write a simple QFont::Style to string converter function yourself.