Qt:编辑条目时 QtAbstractItemView (QTableView) 的背景

发布于 2024-12-14 16:32:53 字数 188 浏览 4 评论 0原文

我有以下问题。 我的 QTableView 的背景颜色设置为黑色,(内容的)颜色设置为白色。因此,白色文本出现在黑色背景上 - 一切似乎都是正确的。但是,当编辑(在编辑模式下键入)时,内容颜色变为黑色,并且由于黑色背景而完全不可见,但编辑工作正常。确认后 - 颜色恢复为白色。如何将当前正在编辑的文本的颜色设置为白色(最好通过样式表)或在这种情况下停止此类更改?

I have the following question.
My QTableView has background color set to black and color (of contents) to white. So, white text appears on a black background - everything seems to be correct. However, when editing (typing in editing mode) content color is changed to black and it becomes completely invisible due to black background, but editing works fine. After confirming - color reverts back to white. How to set color of currently-being-edited text to white (preferably via stylesheets) or stop such change in this case?

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

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

发布评论

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

评论(3

滴情不沾 2024-12-21 16:33:12

首先,当tableview的某个单元格处于编辑状态时,它会被QLineEdit覆盖。您可以通过在样式表中将QLineEdit的背景颜色设置为透明来验证这一点

QLineEdit{
    background-color: transparent;
  }

设置完成后,你会发现单元格处于编辑状态,有正在编辑的文本,也有显示的文本。

因此,解决这个问题的方法是在样式表中设置 QLineEdit 的样式。

QLineEdit {
    background-color: rgb(68,67,49);
    border: 0px;
    font-size:13px;
    font-family:SimHei;
    color:#ADB5BD;
    qproperty-alignment: AlignCenter;
} 

First of all, when a cell of the tableview is in the editing state, it is covered by a QLineEdit.You can verify this by setting the background color of QLineEdit to transparent in your stylesheets

QLineEdit{
    background-color: transparent;
  }

After setting, you will find that the cell is in the editing state, with a text being edited and a displayed text.

Therefore, the solution to this problem is to set the style of QLineEdit in your stylesheets.

QLineEdit {
    background-color: rgb(68,67,49);
    border: 0px;
    font-size:13px;
    font-family:SimHei;
    color:#ADB5BD;
    qproperty-alignment: AlignCenter;
} 

剧终人散尽 2024-12-21 16:33:09

设置调色板终于成功了。

QPalette调色板;

Palette.setColor(QPalette::Text, Qt::white);

qApp->setPalette(palette);

Setting palette worked finally.

QPalette palette;

palette.setColor(QPalette::Text, Qt::white);

qApp->setPalette(palette);

掩饰不了的爱 2024-12-21 16:33:06

您必须在样式表中使用 :edit-focus 和/或 :focus 状态。

QTableView:edit-focus {
   // style here
}

有关所有可用状态的列表,请查看 此处

You have to use the :edit-focus and/or :focus states in your stylesheet.

QTableView:edit-focus {
   // style here
}

For a list of all available states have a look here

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