16,215
社区成员
发帖
与我相关
我的任务
分享
void TableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QString tempsvalue = index.model()->data(index,Qt::DisplayRole).toString();//原来里面的值。
QString svalue;//现在要写到MODEL里面的值
if (index.column()>=1)
{
switch(cur_tabledata->GetColAttr(index.column()))
{
case GL_ATTR_EDIT:
case GL_ATTR_NUMEDIT:
case GL_ATTR_NUMEDIT_DOUBLE:
{
QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
svalue=lineEdit->text();
break;
}
case GL_ATTR_COMBOBOX:
{
QComboBox *comboBox = static_cast<QComboBox*>(editor);
svalue = comboBox->currentText();
break;
}
}
//2013.11.22
if (judge(svalue))//如果不合法则返回TRUE
{
editor->setFocus();
editor->show();
return;
}
model->setData(index, svalue, Qt::EditRole);
}
else
QItemDelegate::setModelData(editor, model, index);
}
这样老是不行啊。
QWidget *TableDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & option ,
const QModelIndex & index ) const
{
if (index.column()>=1)
{
switch(cur_tabledata->GetColAttr(index.column()))
{
case GL_ATTR_EDIT:
case GL_ATTR_NUMEDIT:
case GL_ATTR_NUMEDIT_DOUBLE:
{
QLineEdit *editor = new QLineEdit(parent);
return editor;
}
case GL_ATTR_COMBOBOX:
{
QComboBox *combobox = new QComboBox(parent);
QStringList strlist;
cur_tabledata->m_MenuInfo.GetMenuAllString( index.column(), strlist );
combobox->addItems(strlist);
return combobox;
}
case GL_ATTR_SEARCH:
{
emit callSearch(index.row(),index.column());
return 0;
}
}
}
else
return QItemDelegate::createEditor(parent,option ,index);
}