栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从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())


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661307.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号