【问题标题】:How to clear background in QTreeView during item-edit?如何在项目编辑期间清除 QTreeView 中的背景?
【发布时间】:2013-10-23 18:37:00
【问题描述】:

玩弄一个可编辑的QAbstractItemModel,我注意到旧文本在编辑时不会被删除,因此会产生难看的叠加效果。

我可以使用 Qt 中的 Editable Tree Model Example 重现此内容(单击项目,按 F2,按 End,按几次退格键)。下面的屏幕截图显示了编辑过程中的一个项目,文本“with signals on”已被删除。它就像一个叠加层。旧文本在背景中(蓝底白字),当前文本在上面(蓝底黑字)。

删除/插入字符时效果相同:

屏幕截图来自 Fedora 19 系统,运行 gnome shell。我仍然可以在 Fedora 23 下重现它。

这是用于 gnome shell 的默认 style 中的错误(样式名称:'gtk+')还是打包错误?

我可以解决这个问题吗?

当明确使用其他样式(例如./editabletreemodel -style windows-style fusion)时,背景会在编辑过程中正确清除。

【问题讨论】:

标签: c++ qt qtreeview qtgui


【解决方案1】:

问题在于,在您的情况下,QLineEdit 具有透明背景。您可以尝试设置类似QLineEdit{background-color: white;} 的样式表。

【讨论】:

  • 可以通过-stylesheet FILENAME 选项轻松测试为Qt 应用程序设置样式表。例如:echo QLineEdit, QDateTimeEdit {background-color: white;} > white.css ; ./editabletreemodel -stylesheet white.css.
【解决方案2】:

在 gtk+ Qt 样式修复之前,可以使用如下样式表解决此问题:

#include <QApplication>
#include <QStyle>

int main(int argc, char **argv)
{
  QApplication a(argc, argv);
  // ...
  if (QApplication::style()
      && QApplication::style()->objectName() == "gtk+"
      && qApp->styleSheet().isEmpty()) {
    qApp->setStyleSheet(
        "QLineEdit, QAbstractSpinBox {background-color:white;}");
  }
  // ...
}

【讨论】:

    猜你喜欢
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    相关资源
    最近更新 更多