从pyqt4中的QTableView复制粘贴多个项目?

从pyqt4中的QTableView复制粘贴多个项目?,第1张

从pyqt4中的QTableView复制/粘贴多个项目?
self.tableView.installEventFilters(self)

现在,添加事件过滤器

def eventFilter(self, source, event):        if (event.type() == QtCore.QEvent.KeyPress and event.matches(QtGui.QKeySequence.Copy)): self.copySelection() return True        return super(Window, self).eventFilter(source, event)

复制功能:

def copySelection(self):        selection = self.tableView.selectedIndexes()        if selection: rows = sorted(index.row() for index in selection) columns = sorted(index.column() for index in selection) rowcount = rows[-1] - rows[0] + 1 colcount = columns[-1] - columns[0] + 1 table = [[''] * colcount for _ in range(rowcount)] for index in selection:     row = index.row() - rows[0]     column = index.column() - columns[0]     table[row][column] = index.data() stream = io.StringIO() csv.writer(stream).writerows(table) QtGui.qApp.clipboard().setText(stream.getvalue())


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5663264.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存