我有 Qtablewidget 我已经为该表实现了一个委托
像这样:Num(默认)| 项目(Qcombobox) | -qty-(QdoubleSpinBox)| 价格(QdoubleSpinBox)|小计 (QdoubleSpinBox)
我想使用委托计算每一行的小计(数量 * 价格),但实际上我不知道如何从委托中发出数据
我从我的自定义代表那里试过这个
QWidget *customTableSellDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if(!index.isValid())
return QStyledItemDelegate::createEditor(parent,option,index);
int col= index.column();
if(col == 1)
{
QComboBox *comboboxEditor = new QComboBox(parent);
return comboboxEditor;
}
// col3
else if(col ==2 || col ==3 || col ==4 || col == 5 || col == 6 || col == 7)
{
QDoubleSpinBox *doubleSpinBoxEditor = new QDoubleSpinBox(parent);
doubleSpinBoxEditor->setInputMethodHints(Qt::ImhFormattedNumbersOnly);
doubleSpinBoxEditor->setRange(0.000000,999999999);
doubleSpinBoxEditor->setSuffix(" D.A");
doubleSpinBoxEditor->setDecimals(2);
doubleSpinBoxEditor->setFrame(false);
if(col == 2 || col == 3)
{
connect(doubleSpinBoxEditor,SIGNAL(valueChanged(double)),this,SLOT(testSlot(double)));
}
return doubleSpinBoxEditor;
}else{
return QStyledItemDelegate::createEditor(parent,option,index);
}
}
那么,最好的方法是什么?