本文整理汇总了C++中QVariant::asBool方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::asBool方法的具体用法?C++ QVariant::asBool怎么用?C++ QVariant::asBool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::asBool方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupContents
void KexiKIconTableEdit::setupContents(QPainter *p, bool /*focused*/, const QVariant& val,
QString &/*txt*/, int &/*align*/, int &/*x*/, int &y_offset, int &w, int &h)
{
Q_UNUSED(y_offset);
#if 0
#ifdef Q_WS_WIN
y_offset = -1;
#else
y_offset = 0;
#endif
int s = qMax(h - 5, 12);
s = qMin(h - 3, s);
s = qMin(w - 3, s);//avoid too large box
QRect r(qMax(w / 2 - s / 2, 0) , h / 2 - s / 2 /*- 1*/, s, s);
p->setPen(QPen(colorGroup().text(), 1));
p->drawRect(r);
if (val.asBool()) {
p->drawLine(r.x(), r.y(), r.right(), r.bottom());
p->drawLine(r.x(), r.bottom(), r.right(), r.y());
}
#endif
QString key(val.toString());
QPixmap pm;
if (!key.isEmpty()) {
QPixmap *cached = d->pixmapCache[ key ];
if (cached)
pm = *cached;
if (pm.isNull()) {
//cache pixmap
pm = KIconLoader::global()->loadIcon(key, KIconLoader::Small,
0, KIconLoader::DefaultState , QStringList() , 0L, true/*canReturnNull*/);
if (!pm.isNull())
d->pixmapCache.insert(key, new QPixmap(pm));
}
}
if (p && !pm.isNull())
p->drawPixmap((w - pm.width()) / 2, (h - pm.height()) / 2, pm);
}
示例2: setupContents
void KexiKIconTableEdit::setupContents( QPainter *p, bool /*focused*/, const QVariant& val,
QString &/*txt*/, int &/*align*/, int &/*x*/, int &y_offset, int &w, int &h )
{
Q_UNUSED( y_offset );
#if 0
#ifdef Q_WS_WIN
y_offset = -1;
#else
y_offset = 0;
#endif
int s = QMAX(h - 5, 12);
s = QMIN( h-3, s );
s = QMIN( w-3, s );//avoid too large box
QRect r( QMAX( w/2 - s/2, 0 ) , h/2 - s/2 /*- 1*/, s, s);
p->setPen(QPen(colorGroup().text(), 1));
p->drawRect(r);
if (val.asBool()) {
p->drawLine(r.x(), r.y(), r.right(), r.bottom());
p->drawLine(r.x(), r.bottom(), r.right(), r.y());
}
#endif
QString key = val.toString();
QPixmap *pix = 0;
if (!key.isEmpty() && !(pix = d->pixmapCache[ key ])) {
//cache pixmap
QPixmap pm = KGlobal::iconLoader()->loadIcon( key, KIcon::Small,
0, KIcon::DefaultState, 0L, true/*canReturnNull*/ );
if (!pm.isNull()) {
pix = new QPixmap(pm);
d->pixmapCache.insert(key, pix);
}
}
if (p && pix) {
p->drawPixmap( (w-pix->width())/2, (h-pix->height())/2, *pix );
}
}
示例3: packVariant
static void packVariant( UibStrTable& strings, QDataStream& out,
QVariant value, QString tag = "" )
{
QStringList::ConstIterator s;
Q_UINT8 type = value.type();
if ( tag == "pixmap" ) {
type = QVariant::Pixmap;
} else if ( tag == "image" ) {
type = QVariant::Image;
} else if ( tag == "iconset" ) {
type = QVariant::IconSet;
}
out << type;
switch ( type ) {
case QVariant::String:
case QVariant::Pixmap:
case QVariant::Image:
case QVariant::IconSet:
packString( strings, out, value.asString() );
break;
case QVariant::StringList:
packUInt16( out, value.asStringList().count() );
s = value.asStringList().begin();
while ( s != value.asStringList().end() ) {
packString( strings, out, *s );
++s;
}
break;
case QVariant::Font:
out << value.asFont();
break;
case QVariant::Rect:
packUInt16( out, value.asRect().x() );
packUInt16( out, value.asRect().y() );
packUInt16( out, value.asRect().width() );
packUInt16( out, value.asRect().height() );
break;
case QVariant::Size:
packUInt16( out, value.asSize().width() );
packUInt16( out, value.asSize().height() );
break;
case QVariant::Color:
out << value.asColor();
break;
case QVariant::Point:
packUInt16( out, value.asPoint().x() );
packUInt16( out, value.asPoint().y() );
break;
case QVariant::Int:
packUInt32( out, value.asInt() );
break;
case QVariant::Bool:
out << (Q_UINT8) value.asBool();
break;
case QVariant::Double:
out << value.asDouble();
break;
case QVariant::CString:
packCString( strings, out, value.asCString() );
break;
case QVariant::Cursor:
out << value.asCursor();
break;
case QVariant::Date:
out << value.asDate();
break;
case QVariant::Time:
out << value.asTime();
break;
case QVariant::DateTime:
out << value.asDateTime();
break;
default:
out << value;
}
}