PDA

View Full Version : how can I populate different widget in QTableView according to the first QComboBox



maloudatimes
28th January 2013, 10:14
I have a QTableView(QStandardItemModel) with 2 columns,the first column is ComboDelegate,and i put all database fields into it,now i want put different widget into the second column according to the field shows in the first column,e.g.,the first column's field is course,so the combobox widget would be put into the second column,and the second combobox 's content is history,math,English and so on,another e.g.,the first column's field is borndate,so the date widget will be put into the second column.
What can I do?

QWidget *ComboDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/*option*/,
const QModelIndex &/*index*/) const
{
QComboBox *editor = new QComboBox(parent);
rexdataForm rex(const_cast<QWidget*>(parent));

int length=rex.rexdataModel->columnCount();
for(int i=0;i<length;++i)
{
editor->addItem(rex.rexdataModel->headerData(i,Qt::Horizontal).toString());
}
editor->installEventFilter(const_cast<ComboDelegate*>(this));
qDebug()<<editor->currentText();//here only output the first field.what the heck?

editor->installEventFilter(const_cast<ComboDelegate*>(this));



return editor;
}