我试图用PyQt4创建一个csv格式的文本文件QTableWidget.我想用UTF-8编码来编写文本,因为它包含特殊字符.我使用以下代码:
import codecs
...
myfile = codecs.open(filename, 'w','utf-8')
...
f = result.table.item(i,c).text()
myfile.write(f+";")
Run Code Online (Sandbox Code Playgroud)
它一直有效,直到单元格包含特殊字符.我也尝试过
myfile = open(filename, 'w')
...
f = unicode(result.table.item(i,c).text(), "utf-8")
Run Code Online (Sandbox Code Playgroud)
但是当出现特殊字符时它也会停止.我不知道我做错了什么.
我创建了一个QTableWidget:
self.table = QtGui.QTableWidget()
self.table.setObjectName('table')
self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
verticalLayout.addWidget(self.table)
Run Code Online (Sandbox Code Playgroud)
使用此选项可以选择行,但我不希望用户可以编辑此表的任何单元格.我知道您可以在填充表格时启用每个单元格.但是有可能将整个表格的单元格设置为非活动状态(在填充表格之后),同时仍然可以选择行吗?
TIA Martin