QTableWidget 如何从代码和/或单击中选择一个单元格进行编辑

发布于 2025-01-20 12:37:35 字数 196 浏览 5 评论 0原文

两个部分问题: 我有一个10x10 QTableWidget,每个单元格中都有QTableWidgetItem。 由于某种原因,单击单元格不足以编辑它,我需要双击单元格以输入它。

  1. 是否有一种方法可以将此行为更改为单击

  2. 有没有办法在第1行中选择第二个单元格,默认情况下可以编辑当创建窗口时?

Two part question:
I have a 10x10 QTableWidget with QTableWidgetItem in each cell.
For some reason, clicking on a cell is not sufficient to edit it, I need to double-click the cell to enter it.

  1. Is there a way to change this behavior to single click

  2. Is there a way to have 2nd cell in 1st row selected and ready for editing by default when window is created?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖心男生 2025-01-27 12:37:35

您可以使用 setEditTriggers 以各种方式修改编辑行为。

对于单击,请尝试:

table.setEditTriggers(QAbstractItemView.CurrentChanged)

可以使用 editItem:

table.editItem(table.item(0, 1))

要选择单元格而不对其进行编辑,请使用 设置当前单元格

table.setCurrentCell(0, 1)

You can modify the editing behaviour in various ways with setEditTriggers.

For single-click, try:

table.setEditTriggers(QAbstractItemView.CurrentChanged)

The current edited cell can be set with editItem:

table.editItem(table.item(0, 1))

To select a cell without editing it, use setCurrentCell:

table.setCurrentCell(0, 1)
音栖息无 2025-01-27 12:37:35

您还可以使用 setCurrentCell。

table.setCurrentCell(0,1)

QTableWidget.setCurrentCell(自身,int行,int列)

You can also use setCurrentCell.

table.setCurrentCell(0,1)

QTableWidget.setCurrentCell (self, int row, int column)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文