QItemDelegate use in QTableWidget
Hi,
delegate class
Code:
QCLDelegate
::QCLDelegate(QObject *parent
){
}
{
if (index.column() == 2) {
for(int i = 1970; i < 2014 ; i++){
comboBox->addItem(v.toString());
}
} else if (index.column() == 3) {
comboBox->addItem(tr("BRRip"));
comboBox->addItem(tr("DVDRip"));
comboBox->addItem(tr("Blu-Ray"));
comboBox->addItem(tr("Other"));
} else if (index.column() == 4) {
comboBox->addItem(tr("Yes"));
comboBox->addItem(tr("No"));
}
connect(comboBox, SIGNAL(activated(int)), this, SLOT(emitCommitData()));
return comboBox;
}
and here is how i add to the table widget
Code:
bool QCLMovies
::parseElements(QDomNode &c,
int row
) {
while(!c.isNull()){
if(k.text().isEmpty())
return false;
if(labels.indexOf(k.tagName()) == -1)
return false;
//Adding to table widget
c = c.nextSibling();
}
return true;
}
the class declaration is QCLMovies: public QTableWidget
I am trying to read an XML file into the QTableWidget, with columns 2,3 and 4 as combo boxed and columns 0 and 1 as Qtablewidgetitem (QString), but when i start the application it shows all combo boxes..
Please help me out
Thanks
Re: QItemDelegate use in QTableWidget
in QCLDelegate::createEditor you should write additional condition
Code:
{
if (index.column() == 2 || index.column() == 3 || index.column() == 4) {
//creating and customization of comboboxes
return comboBox;
}
}
you also should be careful in other Delegate's method where an editor is used as method's parameter, you should cast each editor to concert type, because now you have two different editor's type -- QComboBox and QLineEdit.
Re: QItemDelegate use in QTableWidget
Thanks it worked perfectly....