Playing around with an editable QAbstractItemModel, I noticed that the old text is not deleted on edit and thus yields ugly overlay effects.

I can reproduce this with the Editable Tree Model Example from Qt (click item, hit F2, hit End, hit backspace a few times). Below screenshot shows an item during editing, the text 'with signals on' is already deleted. It is like an overlay. The old text is in the background (white on blue) and above that current text is on top (black on blue).

QTreeView while deleting a suffix

Same effect when deleting/inserting characters:

QTreeView overlay during editing

The screenshots are from a Fedora 19 system, running gnome shell. I can still reproduce this under Fedora 23.

Is this a bug in the default style used for gnome shell (style name: 'gtk+') or is it a packaging bug?

Can I work-around this?

When explicitly using another style (e.g. ./editabletreemodel -style windows or -style fusion) the background is cleared correctly during editing.

有帮助吗?

解决方案

The problem is that in your case, the QLineEdit has a transparent background. You can try setting a stylesheet like QLineEdit{background-color: white;}.

其他提示

Until the gtk+ Qt style is fixed, one can work around this with a style sheet like this:

#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;}");
  }
  // ...
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top