2013-04-03 455 views
0

我有一个包含数据的QTableWidget。在qTableWidget单元格中选择文本

在运行时我添加行并在单元格中插入默认数据(标题名称)。

用户将通过删除默认数据来填充数据。

所以我想让最终用户很容易。所以想到在当前添加的行中选择第一个单元格。因此,用户可以直接添加数据并使用Tab移动到下一个单元格。

看看我的快照(行386是在运行时添加的)。

最后一行是我动态添加的内容,行是可编辑的。

enter image description here

我希望它通过选择添加的行

enter image description here

回答

0

的第一单元从Qt文档是这样下面图像:

void QTableWidget::editItem (QTableWidgetItem * item) 

开始编辑项目如果它是可编辑的。

所以,在Python这将是这样的:

def addNewRow(self): 
    row = self.tableWidget.rowCount() 
    #....add data to row cells and set flags to items here... 
    #next line goes at the end of method - after row is populated 
    self.tableWidget.editItem(self.tableWidget.item(row, 0)) 

你必须设置这个标志来的物品:setFlags(Qt.ItemIsEditable | Qt.ItemIsSelectable | Qt.ItemIsEnabled);

相关问题