浏览代码

UI: Dynamically set widget index when renaming sources

Matt Gajownik 5 年之前
父节点
当前提交
c50f488085
共有 1 个文件被更改,包括 4 次插入2 次删除
  1. 4 2
      UI/source-tree.cpp

+ 4 - 2
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                    */