[英]ReadOnly row for more than one QTableWidget with class and get more efficiency
How could I rewrite that code bellow for more then one QTableWidget(not only the self.general_table) ? 我如何才能将代码重写为多个QTableWidget(不仅是self.general_table)? I don't want to put the same code for every table.
我不想为每个表都放置相同的代码。
class QTableWidgetEnDisabledItem(QtGui.QItemDelegate):
"""
Create a readOnly/editable QTableWidgetItem
"""
def __init__(self, parent, state):
self.state = state
QtGui.QItemDelegate.__init__(self, parent)
def createEditor(self, parent, option, index):
item = QtGui.QLineEdit(parent)
if self.state == "disabled":
item.setReadOnly(True)
elif self.state == "enabled":
item.setEnabled(True)
return item
Execution of the class QTableWidgetEnDisabledItem 类QTableWidgetEnDisabledItem的执行
self.Size = QTableWidgetEnDisabledItem(self.general_table, "enabled")
self.general_table.setItemDelegateForRow(index.row(),self.Size)
You could create a list with the tables that you have to use a for to execute the commands that you want. 您可以使用要用于执行所需命令的表创建一个列表。
tables = [self.general_table, self.layers_table]
for table in tables:
itemDelegate = QTableWidgetEnDisabledItem(table, "enabled")
table.setItemDelegateForRow(index.row(), itemDelegate)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.