一:复制
1.获取选中单元格对象的队列;
QModelIndexList selectedIndexes = selectionModel()->selectedIndexes();
2.遍历队列,然后根据当前行和列和上一次是否不同判断,是添加制表符还是换行符:
3.把content内容添加到粘贴板:
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(content);
二:粘贴
1.从粘贴板获取数据
QClipboard *clipboard = QApplication::clipboard();
QString pastedText = clipboard->text();
2.以换行符切割,获取总行数
QStringList rows = pastedText.split("\n", QString::SkipEmptyParts);
3.获取当前选中的行和列
int startRow = currentRow();
int startColumn = currentColumn();
4.遍历,把粘贴板数据粘贴到表格当中,就完成了;