From 78faa2fbe5f88ab3013b65e79ed6c402457e45f1 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 17 Sep 2024 11:27:01 +0200 Subject: [PATCH] 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 --- src/plugins/projectexplorer/projecttreewidget.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/plugins/projectexplorer/projecttreewidget.cpp b/src/plugins/projectexplorer/projecttreewidget.cpp index e1797a8d495..8d9fd339502 100644 --- a/src/plugins/projectexplorer/projecttreewidget.cpp +++ b/src/plugins/projectexplorer/projecttreewidget.cpp @@ -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(p)) { + p->setFocus(); + break; + } + } + + QStyledItemDelegate::destroyEditor(editor, index); + } + private: ProgressIndicatorPainter *findOrCreateIndicatorPainter(const QModelIndex &index) const {