Skip to content

Commit

Permalink
fix tab detatch as window
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Dec 14, 2023
1 parent cfb89c2 commit 5b36407
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions COMTool/main2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit 5b36407

Please sign in to comment.