QTableView 带有所有字段的编辑器

发布于 2025-01-01 22:24:00 字数 440 浏览 2 评论 0原文

我正在尝试修改 QTableView 以始终显示所有编辑器。我同意在所有单元格上调用 openPersistentEditor() 的解决方法。

但是,我希望不选择单元格的内容,并且空字段没有文本光标。

这就是我得到的:

在此处输入图像描述

这就是我想要的:

在此处输入图像描述

我尝试使用 clearSelection()clearFocus() 但这确实不做这个伎俩。如果我单击每个单元格,我会得到所需的结果,并且我可以以编程方式执行相同的操作,但我想知道是否有更直接的方法。

I am trying to modify the QTableView to always show all editors. I am ok with the workaround to call openPersistentEditor() on all cells.

However I'd like the content of the cells to not be selected and no text cursor for empty fields.

This is what I get:

enter image description here

And this is what I'd like to have:

enter image description here

I tried using clearSelection() and clearFocus() but that does not do the trick. If I click on each cell I get the desired result and I could do the same thing programmatically, but I'd to know if there's a more direct way.

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

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

发布评论

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

评论(1

梦里泪两行 2025-01-08 22:24:00

我有这个完全相同的问题。我最终只是调整了 QLineEdits 上的选择颜色和选择背景颜色。您可以在所有 QLineEdit 上执行此操作,也可以仅在自定义 QLineEdit 上执行此操作,方法是为每个编辑器指定一个对象名称并在样式表中引用该名称。

/* applies to all QLineEdits in the application */
QLineEdit { 
  selection-background-color: white;
  selection-color: black
}

/* applies to all QLineEdits with the object name "custom" in the application */
QLineEdit#custom { 
  selection-background-color: white;
  selection-color: black
}

I had this exact same issue. I ended up just adjusting the selection color and selection background color on the QLineEdits. You can do it on all QLineEdits or just on a custom QLineEdit by giving each editor an object name and referencing that in the stylesheet.

/* applies to all QLineEdits in the application */
QLineEdit { 
  selection-background-color: white;
  selection-color: black
}

/* applies to all QLineEdits with the object name "custom" in the application */
QLineEdit#custom { 
  selection-background-color: white;
  selection-color: black
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文