我有一个QTableWidget
,并且使用该方法selectedItems()
来获取我的QTableWidget中选择的所有行。现在,我想将所有这些行复制到other QTableWidget
,是否有特定功能可以执行此操作,或者是否需要使用循环?
如果我需要使用循环,您可以向我解释一下它是如何工作的吗?
谢谢你。
在@Kuba Ober的帮助下,这是我的解决方案:
//Model of my first QTableWidget
QItemSelectionModel *variableModel = ui->variableTableWidget->selectionModel();
//I take the cell selected in my QTableWidget ( I suppose only 1 cell is selected )
QModelIndex item;
QTableWidgetItem* itemCompleteTab = new QTableWidgetItem(); //You can't put a cell to another you have to use a new constructor
foreach (item, variableModel->selectedIndexes()) {
itemCompleteTab->setText(ui->variableTableWidget->item(item.row(),item.column())->text());//Creation of my new cell
ui->visualisationTableWidget->setItem(0,0,itemCompleteTab);//Add in the QTableWidget
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句