MyDialog
::MyDialog(QWidget *parent
){
tableView->setModel(model);
delegate = new ComboBoxDelegate;
tableView->setItemDelegateForColumn(1,delegate);
view2->setModel(model);
view2->setItemDelegateForColumn(1,delegate);
for ( int i = 0; i < model->rowCount(); ++i )
tableView
->openPersistentEditor
( model
->index
(i,
1,
QModelIndex()) );
newRowBtn->setText("add new row");
connect(newRowBtn,SIGNAL(clicked()),this,SLOT(addNewRow()));
vboxlayout->addWidget(tableView);
vboxlayout->addWidget(view2);
vboxlayout
->addWidget
(new QLabel("Vorgang2"));
vboxlayout->addWidget(le);
vboxlayout->addWidget(newRowBtn);
setLayout(vboxlayout);
}
void MyDialog::addNewRow()
{
int row = model->rowCount();
model->insertRow(row);
index = model->index(row, 0);
tableView->setCurrentIndex(index);
tableView->edit(index);
tableView
->openPersistentEditor
( model
->index
(row,
1,
QModelIndex()) );
}
MyDialog::MyDialog(QWidget *parent)
: QWidget(parent)
{
model = new QStandardItemModel(1, 2);
tableView = new QTableView(this);
tableView->setModel(model);
delegate = new ComboBoxDelegate;
tableView->setItemDelegateForColumn(1,delegate);
view2 = new QTableView(this);
view2->setModel(model);
view2->setItemDelegateForColumn(1,delegate);
for ( int i = 0; i < model->rowCount(); ++i )
tableView->openPersistentEditor( model->index(i, 1, QModelIndex()) );
QLineEdit* le = new QLineEdit();
QPushButton *newRowBtn = new QPushButton;
newRowBtn->setText("add new row");
connect(newRowBtn,SIGNAL(clicked()),this,SLOT(addNewRow()));
vboxlayout = new QVBoxLayout(this);
vboxlayout->addWidget(tableView);
vboxlayout->addWidget(view2);
vboxlayout->addWidget(new QLabel("Vorgang2"));
vboxlayout->addWidget(le);
vboxlayout->addWidget(newRowBtn);
setLayout(vboxlayout);
}
void MyDialog::addNewRow()
{
QModelIndex index;
int row = model->rowCount();
model->insertRow(row);
index = model->index(row, 0);
tableView->setCurrentIndex(index);
tableView->edit(index);
tableView->openPersistentEditor( model->index(row, 1, QModelIndex()) );
}
To copy to clipboard, switch view to plain text mode
Bookmarks