简体   繁体   English

pyQt4 - 如何选择表行并禁用编辑单元格

[英]pyQt4 - How to select table rows and disable editing cells

I create a QTableWidget with: 我创建了一个QTableWidget:

self.table = QtGui.QTableWidget()
self.table.setObjectName('table')
self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
verticalLayout.addWidget(self.table)

with this selection it is possible to select rows but I don't want that the user can edit any cells of this table. 使用此选项可以选择行,但我不希望用户可以编辑此表的任何单元格。 I know that you can enable each cell while filling the table. 我知道您可以在填充表格时启用每个单元格。 But is there a possibility to set the cells of the whole table kind of inactive (after the filling of the table) while the selection of the rows is still possible? 但是有可能将整个表格的单元格设置为非活动状态(在填充表格之后),同时仍然可以选择行吗?

TIA Martin TIA Martin

use 采用

self.table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)

( here you can find other triggers , just in case you need them) 这里你可以找到其他触发器 ,以防你需要它们)

You can disable editing by setting the flags ItemIsSelectable and ItemIsEnabled for each item in your table: 您可以通过为表中的每个项目设置标志ItemIsSelectableItemIsEnabled来禁用编辑:

table = QTableWidget(10,10)

for i in range(10):
    for j in range(10):
        item = QTableWidgetItem(str(i*j))
        item.setFlags( Qt.ItemIsSelectable |  Qt.ItemIsEnabled )
        table.setItem(i, j, item)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM