QTableView directly shows QComboBox in one column
-
Hi guys
I want to display QcomboBox in one column. as I searched in forum, I did two things:
- go to createEditor() editor->setautoFillBackGround(true)
2.invoke the openPersistentEditor() in the QtableviewDialog constructor. but it does not work rightly. any advices .thanks in advance.
@
void ImportWellsDialog::setImportTableModel(QObject *obj)
{
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(obj);
m_importTableModel = model;
// ui->importTableView->horizontalHeader()->setVisible(true);
if(model)
{
for( int i = 0; i < model->rowCount(); ++i )
ui->importTableView->openPersistentEditor(model->index(i, 3, QModelIndex()) );// ui->importTableView->openPersistentEditor(model->index(1,3,QModelIndex()));
// ui->importTableView->openPersistentEditor(model->index(2,3,QModelIndex()));
// ui->importTableView->openPersistentEditor(model->index(3,3,QModelIndex()));
// ui->importTableView->openPersistentEditor(model->index(4,3,QModelIndex()));
// ui->importTableView->openPersistentEditor(model->index(5,3,QModelIndex()));
// ui->importTableView->openPersistentEditor(model->index(6,3,QModelIndex()));
// ui->importTableView->openPersistentEditor(model->index(7,3,QModelIndex()));
// ui->importTableView->openPersistentEditor(model->index(1,5,QModelIndex()));
}
ui->importTableView->setModel(model);
}QWidget *WellsComboBoxDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
// if(index.column() == 2)
// {
// for(int i = 0; i < list.size(); i++)
// {
// editor->addItem(list.at(i)->data(0).toString());//abbreviation's role is 0
// }
// Guard::checkIfTrue(QObject::connect(editor, SIGNAL(activated(int )),
// this, SLOT(comboBoxdataChanged(int))),HERE);
// }
if(((index.column() == 3)&&(index.row() != 0)) ||
((index.column() == 5)&&(index.row() == 1)))
{
QComboBox *editor = new QComboBox(parent);
editor->setEditable(false);
editor->setAutoFillBackground(true);
return editor;}
}
@[Edit: Added code formatting. Please wrap your code in @ tags; mlong]
- go to createEditor() editor->setautoFillBackGround(true)
-
I'm not sure what you want to achieve. If you need the combo boxes permanently, try "QAbstractItemView::setIndexWidget() ":http://doc.qt.nokia.com/4.7/qabstractitemview.html#setIndexWidget