本文整理汇总了C++中QVariant::toFont方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::toFont方法的具体用法?C++ QVariant::toFont怎么用?C++ QVariant::toFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::toFont方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: variantToElement
bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e)
{
bool ok = true;
clearAttributes(e);
switch (v.type())
{
case QVariant::String:
e.setTagName("string");
e.setAttribute("value", v.toString().utf8());
break;
case QVariant::CString:
e.setTagName("string");
e.setAttribute("value", v.toCString());
break;
case QVariant::Int:
e.setTagName("int");
e.setAttribute("value", v.toInt());
break;
case QVariant::UInt:
e.setTagName("uint");
e.setAttribute("value", v.toUInt());
break;
case QVariant::Double:
e.setTagName("double");
e.setAttribute("value", v.toDouble());
break;
case QVariant::Bool:
e.setTagName("bool");
e.setAttribute("value", boolString(v.toBool()));
break;
case QVariant::Color:
{
e.setTagName("color");
QColor color = v.toColor();
e.setAttribute("red", color.red());
e.setAttribute("green", color.green());
e.setAttribute("blue", color.blue());
}
break;
case QVariant::Pen:
{
e.setTagName("pen");
QPen pen = v.toPen();
e.setAttribute("red", pen.color().red());
e.setAttribute("green", pen.color().green());
e.setAttribute("blue", pen.color().blue());
e.setAttribute("style", pen.style());
e.setAttribute("cap", pen.capStyle());
e.setAttribute("join", pen.joinStyle());
}
break;
case QVariant::Brush:
{
e.setTagName("brush");
QBrush brush = v.toBrush();
e.setAttribute("red", brush.color().red());
e.setAttribute("green", brush.color().green());
e.setAttribute("blue", brush.color().blue());
e.setAttribute("style", brush.style());
}
break;
case QVariant::Point:
{
e.setTagName("point");
QPoint point = v.toPoint();
e.setAttribute("x", point.x());
e.setAttribute("y", point.y());
}
break;
case QVariant::Rect:
{
e.setTagName("rect");
QRect rect = v.toRect();
e.setAttribute("x", rect.x());
e.setAttribute("y", rect.y());
e.setAttribute("width", rect.width());
e.setAttribute("height", rect.height());
}
break;
case QVariant::Size:
{
e.setTagName("size");
QSize qsize = v.toSize();
e.setAttribute("width", qsize.width());
e.setAttribute("height", qsize.height());
}
break;
case QVariant::Font:
{
e.setTagName("font");
QFont f(v.toFont());
e.setAttribute("family", f.family());
e.setAttribute("pointsize", f.pointSize());
e.setAttribute("bold", boolString(f.bold()));
e.setAttribute("italic", boolString(f.italic()));
e.setAttribute("underline", boolString(f.underline()));
e.setAttribute("strikeout", boolString(f.strikeOut()));
}
//.........这里部分代码省略.........
示例2: elementToVariant
/*!
Interprets element \a e as variant and returns the result of the interpretation.
*/
QVariant DomTool::elementToVariant( const QDomElement& e, const QVariant& defValue, QString &comment )
{
QVariant v;
if ( e.tagName() == "rect" ) {
QDomElement n3 = e.firstChild().toElement();
int x = 0, y = 0, w = 0, h = 0;
while ( !n3.isNull() ) {
if ( n3.tagName() == "x" )
x = n3.firstChild().toText().data().toInt();
else if ( n3.tagName() == "y" )
y = n3.firstChild().toText().data().toInt();
else if ( n3.tagName() == "width" )
w = n3.firstChild().toText().data().toInt();
else if ( n3.tagName() == "height" )
h = n3.firstChild().toText().data().toInt();
n3 = n3.nextSibling().toElement();
}
v = QVariant( QRect( x, y, w, h ) );
} else if ( e.tagName() == "point" ) {
QDomElement n3 = e.firstChild().toElement();
int x = 0, y = 0;
while ( !n3.isNull() ) {
if ( n3.tagName() == "x" )
x = n3.firstChild().toText().data().toInt();
else if ( n3.tagName() == "y" )
y = n3.firstChild().toText().data().toInt();
n3 = n3.nextSibling().toElement();
}
v = QVariant( QPoint( x, y ) );
} else if ( e.tagName() == "size" ) {
QDomElement n3 = e.firstChild().toElement();
int w = 0, h = 0;
while ( !n3.isNull() ) {
if ( n3.tagName() == "width" )
w = n3.firstChild().toText().data().toInt();
else if ( n3.tagName() == "height" )
h = n3.firstChild().toText().data().toInt();
n3 = n3.nextSibling().toElement();
}
v = QVariant( QSize( w, h ) );
} else if ( e.tagName() == "color" ) {
v = QVariant( readColor( e ) );
} else if ( e.tagName() == "font" ) {
QDomElement n3 = e.firstChild().toElement();
QFont f( defValue.toFont() );
while ( !n3.isNull() ) {
if ( n3.tagName() == "family" )
f.setFamily( n3.firstChild().toText().data() );
else if ( n3.tagName() == "pointsize" )
f.setPointSize( n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "bold" )
f.setBold( n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "italic" )
f.setItalic( n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "underline" )
f.setUnderline( n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "strikeout" )
f.setStrikeOut( n3.firstChild().toText().data().toInt() );
n3 = n3.nextSibling().toElement();
}
v = QVariant( f );
} else if ( e.tagName() == "string" ) {
v = QVariant( e.firstChild().toText().data() );
QDomElement n = e;
n = n.nextSibling().toElement();
if ( n.tagName() == "comment" )
comment = n.firstChild().toText().data();
} else if ( e.tagName() == "cstring" ) {
v = QVariant( QCString( e.firstChild().toText().data() ) );
} else if ( e.tagName() == "number" ) {
bool ok = TRUE;
v = QVariant( e.firstChild().toText().data().toInt( &ok ) );
if ( !ok )
v = QVariant( e.firstChild().toText().data().toDouble() );
} else if ( e.tagName() == "bool" ) {
QString t = e.firstChild().toText().data();
v = QVariant( t == "true" || t == "1", 0 );
} else if ( e.tagName() == "pixmap" ) {
v = QVariant( e.firstChild().toText().data() );
} else if ( e.tagName() == "iconset" ) {
v = QVariant( e.firstChild().toText().data() );
} else if ( e.tagName() == "image" ) {
v = QVariant( e.firstChild().toText().data() );
} else if ( e.tagName() == "enum" ) {
v = QVariant( e.firstChild().toText().data() );
} else if ( e.tagName() == "set" ) {
v = QVariant( e.firstChild().toText().data() );
} else if ( e.tagName() == "sizepolicy" ) {
QDomElement n3 = e.firstChild().toElement();
QSizePolicy sp;
while ( !n3.isNull() ) {
if ( n3.tagName() == "hsizetype" )
sp.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "vsizetype" )
sp.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "horstretch" )
sp.setHorStretch( n3.firstChild().toText().data().toInt() );
//.........这里部分代码省略.........
示例3: elementToVariant
/*!
Interprets element \a e as variant and returns the result of the interpretation.
*/
QVariant DomTool::elementToVariant( const QDomElement& e, const QVariant& defValue, QString *comment )
{
QVariant v;
if ( e.tagName() == "rect" ) {
QDomElement n3 = e.firstChild().toElement();
int x = 0, y = 0, w = 0, h = 0;
while ( !n3.isNull() ) {
if ( n3.tagName() == "x" )
x = n3.firstChild().toText().data().toInt();
else if ( n3.tagName() == "y" )
y = n3.firstChild().toText().data().toInt();
else if ( n3.tagName() == "width" )
w = n3.firstChild().toText().data().toInt();
else if ( n3.tagName() == "height" )
h = n3.firstChild().toText().data().toInt();
n3 = n3.nextSibling().toElement();
}
v = QVariant( QRect( x, y, w, h ) );
} else if ( e.tagName() == "point" ) {
QDomElement n3 = e.firstChild().toElement();
int x = 0, y = 0;
while ( !n3.isNull() ) {
if ( n3.tagName() == "x" )
x = n3.firstChild().toText().data().toInt();
else if ( n3.tagName() == "y" )
y = n3.firstChild().toText().data().toInt();
n3 = n3.nextSibling().toElement();
}
v = QVariant( QPoint( x, y ) );
} else if ( e.tagName() == "size" ) {
QDomElement n3 = e.firstChild().toElement();
int w = 0, h = 0;
while ( !n3.isNull() ) {
if ( n3.tagName() == "width" )
w = n3.firstChild().toText().data().toInt();
else if ( n3.tagName() == "height" )
h = n3.firstChild().toText().data().toInt();
n3 = n3.nextSibling().toElement();
}
v = QVariant( QSize( w, h ) );
} else if ( e.tagName() == "color" ) {
v = QVariant( readColor( e ) );
} else if ( e.tagName() == "font" ) {
QDomElement n3 = e.firstChild().toElement();
QFont f( defValue.toFont() );
while ( !n3.isNull() ) {
if ( n3.tagName() == "family" )
f.setFamily( n3.firstChild().toText().data() );
else if ( n3.tagName() == "pointsize" )
f.setPointSize( n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "bold" )
f.setBold( n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "italic" )
f.setItalic( n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "underline" )
f.setUnderline( n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "strikeout" )
f.setStrikeOut( n3.firstChild().toText().data().toInt() );
n3 = n3.nextSibling().toElement();
}
v = QVariant( f );
} else if ( e.tagName() == "string" ) {
v = QVariant( e.firstChild().toText().data() );
QDomElement n = e;
n = n.nextSibling().toElement();
if ( comment && n.tagName() == "comment" )
*comment = n.firstChild().toText().data();
} else if ( e.tagName() == "cstring" ) {
v = QVariant( QCString( e.firstChild().toText().data() ) );
} else if ( e.tagName() == "number" ) {
v = QVariant( e.firstChild().toText().data().toInt() );
} else if ( e.tagName() == "bool" ) {
QString t = e.firstChild().toText().data();
v = QVariant( t == "true" || t == "1", 0 );
} else if ( e.tagName() == "pixmap" ) {
v = QVariant( e.firstChild().toText().data() );
} else if ( e.tagName() == "iconset" ) {
v = QVariant( e.firstChild().toText().data() );
} else if ( e.tagName() == "image" ) {
v = QVariant( e.firstChild().toText().data() );
} else if ( e.tagName() == "enum" ) {
v = QVariant( e.firstChild().toText().data() );
} else if ( e.tagName() == "set" ) {
v = QVariant( e.firstChild().toText().data() );
} else if ( e.tagName() == "sizepolicy" ) {
QDomElement n3 = e.firstChild().toElement();
QSizePolicy sp;
while ( !n3.isNull() ) {
if ( n3.tagName() == "hsizetype" )
sp.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
else if ( n3.tagName() == "vsizetype" )
sp.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
n3 = n3.nextSibling().toElement();
}
v = QVariant( sp );
} else if ( e.tagName() == "cursor" ) {
v = QVariant( QCursor( e.firstChild().toText().data().toInt() ) );
//.........这里部分代码省略.........
示例4: writeEntry
void KConfigBase::writeEntry(const char *pKey, const QVariant &prop, bool bPersistent, bool bGlobal, bool bNLS)
{
switch(prop.type())
{
case QVariant::Invalid:
writeEntry(pKey, "", bPersistent, bGlobal, bNLS);
return;
case QVariant::String:
writeEntry(pKey, prop.toString(), bPersistent, bGlobal, bNLS);
return;
case QVariant::StringList:
writeEntry(pKey, prop.toStringList(), ',', bPersistent, bGlobal, bNLS);
return;
case QVariant::List:
{
QValueList< QVariant > list = prop.toList();
QValueList< QVariant >::ConstIterator it = list.begin();
QValueList< QVariant >::ConstIterator end = list.end();
QStringList strList;
for(; it != end; ++it)
strList.append((*it).toString());
writeEntry(pKey, strList, ',', bPersistent, bGlobal, bNLS);
return;
}
case QVariant::Font:
writeEntry(pKey, prop.toFont(), bPersistent, bGlobal, bNLS);
return;
case QVariant::Point:
writeEntry(pKey, prop.toPoint(), bPersistent, bGlobal, bNLS);
return;
case QVariant::Rect:
writeEntry(pKey, prop.toRect(), bPersistent, bGlobal, bNLS);
return;
case QVariant::Size:
writeEntry(pKey, prop.toSize(), bPersistent, bGlobal, bNLS);
return;
case QVariant::Color:
writeEntry(pKey, prop.toColor(), bPersistent, bGlobal, bNLS);
return;
case QVariant::Int:
writeEntry(pKey, prop.toInt(), bPersistent, bGlobal, bNLS);
return;
case QVariant::UInt:
writeEntry(pKey, prop.toUInt(), bPersistent, bGlobal, bNLS);
return;
case QVariant::LongLong:
writeEntry(pKey, prop.toLongLong(), bPersistent, bGlobal, bNLS);
return;
case QVariant::ULongLong:
writeEntry(pKey, prop.toULongLong(), bPersistent, bGlobal, bNLS);
return;
case QVariant::Bool:
writeEntry(pKey, prop.toBool(), bPersistent, bGlobal, bNLS);
return;
case QVariant::Double:
writeEntry(pKey, prop.toDouble(), bPersistent, bGlobal, 'g', 6, bNLS);
return;
case QVariant::DateTime:
writeEntry(pKey, prop.toDateTime(), bPersistent, bGlobal, bNLS);
return;
case QVariant::Date:
writeEntry(pKey, QDateTime(prop.toDate()), bPersistent, bGlobal, bNLS);
return;
case QVariant::Pixmap:
case QVariant::Image:
case QVariant::Brush:
case QVariant::Palette:
case QVariant::ColorGroup:
case QVariant::Map:
case QVariant::IconSet:
case QVariant::CString:
case QVariant::PointArray:
case QVariant::Region:
case QVariant::Bitmap:
case QVariant::Cursor:
case QVariant::SizePolicy:
case QVariant::Time:
case QVariant::ByteArray:
case QVariant::BitArray:
case QVariant::KeySequence:
case QVariant::Pen:
break;
}
Q_ASSERT(0);
}
示例5: process
//.........这里部分代码省略.........
for(uint i= 1; i < st.count(); i++)t+='/'+st.at(i);
att2->setText(1,t);
}
else if(val.type() == QVariant::String)att2->setText(1,'"'+val.toString()+'"');
else if(val.type() == QVariant::CString)att2->setText(1,'"'+val.toCString()+'"');
else if(val.type() == QVariant::Bool){
if(val.toBool())att2->setText(1,"True");
else att2->setText(1,"False");
}
else if(val.type() == QVariant::Int)att2->setText(1,QString::number(val.toInt()));
else if(val.type() == QVariant::UInt)att2->setText(1,QString::number(val.toUInt()));
else if(val.type() == QVariant::Double)att2->setText(1,QString::number(val.toDouble()));
else if(val.type() == QVariant::Rect){
const QRect r = val.toRect();
att2->setText(1,'[' + QString::number(r.left()) + ',' + QString::number(r.top())+
',' + QString::number(r.right()) + ',' + QString::number(r.bottom())+']');
}
else if(val.type() == QVariant::Region){
const QRegion reg = val.toRegion();
QRect r = reg.boundingRect();
att2->setText(1,'[' + QString::number(r.left()) + ',' + QString::number(r.top())+
',' + QString::number(r.right()) + ',' + QString::number(r.bottom())+"],");
}
else if(val.type() == QVariant::Size){
const QSize s = val.toSize();
att2->setText(1,'[' + QString::number(s.width()) + ',' + QString::number(s.height())+']');
}
else if(val.type() == QVariant::Point){
const QPoint p = val.toPoint();
att2->setText(1,'[' + QString::number(p.x()) + ',' + QString::number(p.y())+']');
}
else if(val.type() == QVariant::Color){
const QColor c = val.toColor();
att2->setText(1,'[' + QString::number(c.red()) + ',' +
QString::number(c.green()) + ',' +
QString::number(c.blue()) + ']');
}
else if(val.type() == QVariant::ColorGroup){
const QColorGroup cg = val.toColorGroup();
QColor c = cg.base();
att2->setText(1,'[' + QString::number(c.red()) + ',' +
QString::number(c.green()) + ',' +
QString::number(c.blue()) + "], ...");
}
else if(val.type() == QVariant::Font){
const QFont f = val.toFont();
QString text = '\'' + f.family() + "', " + QString::number(f.pointSize())
+ ", " + QString::number(f.weight());
if(f.italic())text+=", italic";
att2->setText(1,text);
}
else if(val.type() == QVariant::SizePolicy){
QSizePolicy sp = val.toSizePolicy();
QString text;
if(sp.horData() == QSizePolicy::Fixed)text+="Fixed";
else if(sp.horData() == QSizePolicy::Minimum )text+="Minimum";
else if(sp.horData() == QSizePolicy::Maximum )text+="Maximum";
else if(sp.horData() == QSizePolicy::Preferred )text+="Preferred";
else if(sp.horData() == QSizePolicy::MinimumExpanding )text+="MinimumExpanding";
else if(sp.horData() == QSizePolicy::Expanding )text+="Expanding";
text +='/';
if(sp.verData() == QSizePolicy::Fixed)text+="Fixed";
else if(sp.verData() == QSizePolicy::Minimum )text+="Minimum";
else if(sp.verData() == QSizePolicy::Maximum )text+="Maximum";
else if(sp.verData() == QSizePolicy::Preferred )text+="Preferred";
else if(sp.verData() == QSizePolicy::MinimumExpanding )text+="MinimumExpanding";
else if(sp.verData() == QSizePolicy::Expanding )text+="Expanding";
att2->setText(1,text);
}
else if(val.type() == QVariant::Pixmap){
QPixmap pix = val.toPixmap();
if(!pix.isNull())att2->setPixmap(1,pix);
}
else if(val.type() == QVariant::Cursor){
const QCursor cur = val.toCursor();
const QBitmap * pix = cur.bitmap();
if(pix && !pix->isNull())att2->setPixmap(1,*pix);
else att2->setText(1,QString::number(cur.shape()));
}
}
}
}
const QObjectList * roots = obj->children();
if(roots != NULL){
__current = new QListViewItem(__current,att,"children","ptr="+QString::number((unsigned long)roots),
"List<QObject>["+QString::number(roots->count())+"]");
__current->setPixmap(0,__pixappe);
QObjectList r(*roots);
uint size = r.count();
for(uint i = 0; i < size; i++ ){
QObject * _obj = r.at(i);
process(_obj);
}
}
__current = buf;
}
}
示例6: variantToElement
bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e)
{
bool ok = true;
clearAttributes(e);
switch (v.type())
{
case QVariant::String:
e.setTagName("string");
e.setAttribute("value", v.toString().utf8());
break;
case QVariant::CString:
e.setTagName("string");
e.setAttribute("value", v.toCString());
break;
case QVariant::Int:
e.setTagName("int");
e.setAttribute("value", v.toInt());
break;
case QVariant::UInt:
e.setTagName("uint");
e.setAttribute("value", v.toUInt());
break;
case QVariant::Double:
e.setTagName("double");
e.setAttribute("value", v.toDouble());
break;
case QVariant::Bool:
e.setTagName("bool");
e.setAttribute("value", boolString(v.toBool()));
break;
case QVariant::Color:
{
e.setTagName("color");
QColor color = v.toColor();
e.setAttribute("red", color.red());
e.setAttribute("green", color.green());
e.setAttribute("blue", color.blue());
}
break;
case QVariant::Point:
{
e.setTagName("point");
QPoint point = v.toPoint();
e.setAttribute("x", point.x());
e.setAttribute("y", point.y());
}
break;
case QVariant::Rect:
{
e.setTagName("rect");
QRect rect = v.toRect();
e.setAttribute("x", rect.x());
e.setAttribute("y", rect.y());
e.setAttribute("width", rect.width());
e.setAttribute("height", rect.height());
}
break;
case QVariant::Size:
{
e.setTagName("size");
QSize qsize = v.toSize();
e.setAttribute("width", qsize.width());
e.setAttribute("height", qsize.height());
}
break;
case QVariant::Font:
{
e.setTagName("font");
QFont f(v.toFont());
e.setAttribute("family", f.family());
e.setAttribute("pointsize", f.pointSize());
e.setAttribute("bold", boolString(f.bold()));
e.setAttribute("italic", boolString(f.italic()));
e.setAttribute("underline", boolString(f.underline()));
e.setAttribute("strikeout", boolString(f.strikeOut()));
}
break;
case QVariant::SizePolicy:
{
e.setTagName("sizepolicy");
QSizePolicy sp(v.toSizePolicy());
e.setAttribute("hsizetype", sp.horData());
e.setAttribute("vsizetype", sp.verData());
#if (QT_VERSION >= 300)
e.setAttribute("horstretch", sp.horStretch());
e.setAttribute("verstretch", sp.verStretch());
#endif
}
break;
case QVariant::Cursor:
e.setTagName("cursor");
e.setAttribute("shape", v.toCursor().shape());
break;
case QVariant::StringList:
{
e.setTagName("stringlist");
uint j;
//.........这里部分代码省略.........