From c50f488085b45cde2a78aa1e333f13b57c74fa0a Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Wed, 4 Mar 2020 19:22:30 +1100 Subject: [PATCH] UI: Dynamically set widget index when renaming sources --- UI/source-tree.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/UI/source-tree.cpp b/UI/source-tree.cpp index fa21620d4..fdd4c37c8 100644 --- a/UI/source-tree.cpp +++ b/UI/source-tree.cpp @@ -318,12 +318,13 @@ bool SourceTreeItem::IsEditing() void SourceTreeItem::EnterEditMode() { setFocusPolicy(Qt::StrongFocus); + int index = boxLayout->indexOf(label); boxLayout->removeWidget(label); editor = new QLineEdit(label->text()); editor->setStyleSheet("background: none"); editor->selectAll(); editor->installEventFilter(this); - boxLayout->insertWidget(2, editor); + boxLayout->insertWidget(index, editor); setFocusProxy(editor); } @@ -338,11 +339,12 @@ void SourceTreeItem::ExitEditMode(bool save) std::string newName = QT_TO_UTF8(editor->text()); setFocusProxy(nullptr); + int index = boxLayout->indexOf(editor); boxLayout->removeWidget(editor); delete editor; editor = nullptr; setFocusPolicy(Qt::NoFocus); - boxLayout->insertWidget(2, label); + boxLayout->insertWidget(index, label); /* ----------------------------------------- */ /* check for empty string */ -- GitLab