Answer the question
In order to leave comments, you need to log in
How to copy selected data from one TableView to another TableView?
Hello there are two tables qTableView.
When you double-click on a cell in the first one, you need to move this cell to the second table.
did it this way:
void reportHelp::on_tableView_doubleClicked(const QModelIndex &index)
{
QStandardItemModel *model = new QStandardItemModel;
QStandardItem *item;
QStringList horizontalHeader;
horizontalHeader.append("Судовладельцы");
model->setHorizontalHeaderLabels(horizontalHeader);
//проверка
ui->textEdit->setText(index.data().toString());
ui->lineEdit->setText(QString::number(row));
item = new QStandardItem(QString(index.data().toString()));
model->insertRow(row,item);
row++;
ui->tableView_2->setModel(model);
ui->tableView_2->resizeRowsToContents();
ui->tableView_2->resizeColumnsToContents();
}
Answer the question
In order to leave comments, you need to log in
the problem was solved through tableWidget
void reportHelp::on_tableView_doubleClicked(const QModelIndex &index)
{
ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1);
QTableWidgetItem* item = new QTableWidgetItem;
item->setText(index.data().toString());
item->setTextAlignment(Qt::AlignCenter);
ui->tableWidget->setItem(ui->tableWidget->rowCount() - 1, 0, item);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question