本文整理汇总了C++中QVariant::canCast方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::canCast方法的具体用法?C++ QVariant::canCast怎么用?C++ QVariant::canCast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::canCast方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
bool
StdWidgetFactory::readSpecialProperty(const QCString &classname, QDomElement &node, QWidget *w, KFormDesigner::ObjectTreeItem *)
{
QString tag = node.tagName();
QString name = node.attribute("name");
if((tag == "item") && (classname == "KComboBox"))
{
KComboBox *combo = (KComboBox*)w;
QVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name);
if(val.canCast(QVariant::Pixmap))
combo->insertItem(val.toPixmap());
else
combo->insertItem(val.toString());
return true;
}
if((tag == "item") && (classname == "KListBox"))
{
KListBox *listbox = (KListBox*)w;
QVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name);
if(val.canCast(QVariant::Pixmap))
listbox->insertItem(val.toPixmap());
else
listbox->insertItem(val.toString());
return true;
}
if((tag == "column") && (classname == "KListView"))
{
KListView *listview = (KListView*)w;
int id=0;
for(QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
{
QString prop = n.toElement().attribute("name");
QVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), w, name);
if(prop == "text")
id = listview->addColumn(val.toString());
else if(prop == "width")
listview->setColumnWidth(id, val.toInt());
else if(prop == "resizable")
listview->header()->setResizeEnabled(val.toBool(), id);
else if(prop == "clickable")
listview->header()->setClickEnabled(val.toBool(), id);
else if(prop == "fullwidth")
listview->header()->setStretchEnabled(val.toBool(), id);
}
return true;
}
else if((tag == "item") && (classname == "KListView"))
{
KListView *listview = (KListView*)w;
readListItem(node, 0, listview);
return true;
}
return false;
}
示例2: setTextColor
void KstBindLegend::setTextColor(KJS::ExecState *exec, const KJS::Value& value) {
QVariant cv = KJSEmbed::convertToVariant(exec, value);
if (!cv.canCast(QVariant::Color)) {
return createPropertyTypeError(exec);
}
KstViewLegendPtr d = makeLegend(_d);
if (d) {
KstWriteLocker rl(d);
d->setForegroundColor(cv.toColor());
KstApp::inst()->paintAll(KstPainter::P_PAINT);
}
}
示例3: setColor
void KstBindCurve::setColor(KJS::ExecState *exec, const KJS::Value& value) {
QVariant cv = KJSEmbed::convertToVariant(exec, value);
if (!cv.canCast(QVariant::Color)) {
KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
exec->setException(eobj);
return;
}
KstVCurvePtr d = makeCurve(_d);
if (d) {
KstWriteLocker rl(d);
d->setColor(cv.toColor());
}
}
示例4: setBorderColor
void KstBindEllipse::setBorderColor(KJS::ExecState *exec, const KJS::Value& value) {
QVariant cv = KJSEmbed::convertToVariant(exec, value);
if (!cv.canCast(QVariant::Color)) {
KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
exec->setException(eobj);
return;
}
KstViewEllipsePtr d = makeEllipse(_d);
if (d) {
KstWriteLocker rl(d);
d->setBorderColor(cv.toColor());
KstApp::inst()->paintAll(KstPainter::P_PAINT);
}
}
示例5: setValue
void PComboBox::setValue(const QVariant &value, bool emitChange)
{
#if QT_VERSION >= 0x030100
if (!value.isNull())
#else
if (value.canCast(QVariant::String))
#endif
{
disconnect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
m_edit->setCurrentText(findDescription(value));
connect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
if (emitChange)
emit propertyChanged(m_property, value);
}
示例6: calculate
bool Matrix::calculate(int startRow, int endRow, int startCol, int endCol)
{
QApplication::setOverrideCursor(waitCursor);
Script *script = scriptEnv->newScript(formula_str, this, QString("<%1>").arg(name()));
connect(script, SIGNAL(error(const QString&,const QString&,int)), scriptEnv, SIGNAL(error(const QString&,const QString&,int)));
connect(script, SIGNAL(print(const QString&)), parent()->parent()->parent(), SLOT(scriptPrint(const QString&)));
if (!script->compile())
{
QApplication::restoreOverrideCursor();
return false;
}
int rows=d_table->numRows();
int cols=d_table->numCols();
if (endCol >= cols)
d_table->setNumCols(endCol+1);
if (endRow >= rows)
d_table->setNumRows(endRow+1);
QVariant ret;
saveCellsToMemory();
for (int row=startRow; row<=endRow; row++)
for (int col=startCol; col<=endCol; col++)
{
script->setInt(row+1, "i");
script->setInt(row+1, "row");
script->setInt(col+1, "j");
script->setInt(col+1, "col");
ret = script->eval();
if (ret.type()==QVariant::Int || ret.type()==QVariant::UInt || ret.type()==QVariant::LongLong || ret.type()==QVariant::ULongLong)
d_table->setText(row, col, ret.toString());
else if(ret.canCast(QVariant::Double))
d_table->setText(row,col,QString::number(ret.toDouble(),txt_format, num_precision));
else {
d_table->setText(row,col,"");
QApplication::restoreOverrideCursor();
return false;
}
}
forgetSavedCells();
emit modifiedWindow(this);
QApplication::restoreOverrideCursor();
return true;
}
示例7: QRect
void
KexiBlobTableEdit::setupContents( QPainter *p, bool focused, const QVariant& val,
QString &txt, int &align, int &x, int &y_offset, int &w, int &h )
{
Q_UNUSED(focused);
Q_UNUSED(txt);
Q_UNUSED(align);
//! @todo optimize: load to m_pixmap, downsize
QPixmap pixmap;
x = 0;
w -= 1; //a place for border
h -= 1; //a place for border
if (p && val.canCast(QVariant::ByteArray) && pixmap.loadFromData(val.toByteArray())) {
KexiUtils::drawPixmap( *p, 0/*lineWidth*/, QRect(x, y_offset, w, h),
pixmap, Qt::AlignCenter, true/*scaledContents*/, true/*keepAspectRatio*/);
}
}
示例8: cellEdited
void Matrix::cellEdited(int row,int col)
{
Script *script = scriptEnv->newScript(d_table->text(row,col),this,QString("<%1_%2_%3>").arg(name()).arg(row).arg(col));
connect(script, SIGNAL(error(const QString&,const QString&,int)), scriptEnv, SIGNAL(error(const QString&,const QString&,int)));
script->setInt(row+1, "row");
script->setInt(row+1, "i");
script->setInt(col+1, "col");
script->setInt(col+1, "j");
QVariant ret = script->eval();
if(ret.type()==QVariant::Int || ret.type()==QVariant::UInt || ret.type()==QVariant::LongLong || ret.type()==QVariant::ULongLong)
d_table->setText(row, col, ret.toString());
else if(ret.canCast(QVariant::Double))
d_table->setText(row, col, QString::number(ret.toDouble(), txt_format, num_precision));
else
d_table->setText(row, col, "");
emit modifiedWindow(this);
}