ProjectExplorer: Make sure to keep focus on the project tree

... after renaming files.
The problem was as follows:
  - The user renames e.g. a header file myclass.h, resulting in a focus
    change to a newly created line edit.
  - We ask them whether myclass.cpp should also be renamed, resulting in
    a focus change to the message box.
  - After the message box closes, the line edit gets destroyed before
    the focus can change back to it.
  - The focus goes to some random widget.
Prevent this by explicitly giving the project tree widget the focus when
the line edit gets destroyed.

Fixes: QTCREATORBUG-30926
Change-Id: I36ae61219ce59966d3758c4614e3c49d286af160
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2024-09-17 11:27:01 +02:00
parent 932a05c3bb
commit 78faa2fbe5

View File

@@ -100,6 +100,19 @@ public:
}
}
void destroyEditor(QWidget *editor, const QModelIndex &index) const final
{
// QTCREATORBUG-30926
for (QWidget *p = editor->parentWidget(); p; p = p->parentWidget()) {
if (qobject_cast<ProjectTreeWidget *>(p)) {
p->setFocus();
break;
}
}
QStyledItemDelegate::destroyEditor(editor, index);
}
private:
ProgressIndicatorPainter *findOrCreateIndicatorPainter(const QModelIndex &index) const
{