From 5b36407dac2e57c5b8dd2ac59f7c221b448e68ef Mon Sep 17 00:00:00 2001 From: Neucrack Date: Thu, 14 Dec 2023 23:23:51 +0800 Subject: [PATCH] fix tab detatch as window --- COMTool/main2.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/COMTool/main2.py b/COMTool/main2.py index 842556d..32464aa 100644 --- a/COMTool/main2.py +++ b/COMTool/main2.py @@ -473,13 +473,25 @@ def onTabDoubleClicked(self, idx): item = self.getCurrentItem() self.tabWidget.removeTab(idx) parent = item.widget.parent() - item.widget.setWindowFlag(Qt.Window) + item.widget.setWindowFlag(Qt.Window) # this method is not stable in QT, do not use it + # item.widget.setParent(None) item.widget.setWindowTitle(item.name) - item.widget.closeEvent = lambda event: self.recoverTab(item, parent) + item.widget.closeEvent = lambda event: self.onPluginWindowClose(item, parent) item.widget.show() + def onPluginWindowClose(self, item, parent): + self.recoverTab(item, parent) + def recoverTab(self, item, parent): + def add(i): + self.tabWidget.insertTab(i, item.widget, item.name) + self.tabWidget.setCurrentIndex(i) + item.widget.setWindowFlag(Qt.Window, False) + # item.widget.setParent(parent) + status = item.plugin.getConnStatus() + self.setTabIcon(status, i) # prevent close and add this widget to tab + insertIdx = self.tabWidget.count() idx = self.items.index(item) for i in range(self.tabWidget.count()): widget = self.tabWidget.widget(i) @@ -488,12 +500,9 @@ def recoverTab(self, item, parent): idx2 = self.items.index(_item) break if idx2 > idx: - self.tabWidget.insertTab(i, item.widget, item.name) - self.tabWidget.setCurrentIndex(i) - item.widget.setWindowFlag(Qt.Window, False) - status = item.plugin.getConnStatus() - self.setTabIcon(status, i) + insertIdx = i break + add(insertIdx) def updateStyle(self, widget):