Hi,
delegate class
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;
}
QCLDelegate::QCLDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
QWidget *QCLDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & /* option */,
const QModelIndex &index) const
{
QComboBox *comboBox = new QComboBox(parent);
if (index.column() == 2) {
for(int i = 1970; i < 2014 ; i++){
QVariant v(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;
}
To copy to clipboard, switch view to plain text mode
and here is how i add to the table widget
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;
}
bool QCLMovies::parseElements(QDomNode &c, int row)
{
while(!c.isNull()){
QDomElement k = c.toElement();
if(k.text().isEmpty())
return false;
if(labels.indexOf(k.tagName()) == -1)
return false;
//Adding to table widget
setItem(row, labels.indexOf(k.tagName()), new QTableWidgetItem(k.text()));
c = c.nextSibling();
}
return true;
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks