PyQt - 隐藏 MainWindow 并显示 QDialog 而任务栏图标不消失

PyQt - Hide MainWindow and show QDialog without the taskbar icon disappearing

我一直在使用这个例子中的代码 PyQt: How to hide QMainWindow:

class Dialog_02(QtGui.QMainWindow):
    def __init__(self, parent):
        super(Dialog_02, self).__init__(parent)
        # ensure this window gets garbage-collected when closed
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    ...    

    def closeAndReturn(self):
        self.close()
        self.parent().show()

class Dialog_01(QtGui.QMainWindow):
    ...

    def callAnotherQMainWindow(self):
        self.hide()
        self.dialog_02 = Dialog_02(self)
        self.dialog_02.show()

它可以工作,但是当打开第二个 window 时,window 的任务栏图标不显示。我也尝试过将 QtGui.QDialog 用于 Dialog_02,但这给了我相同的结果。

我该如何解决这个问题?

编辑:我在 Windows 10

只是猜测(因为我不知道你在什么平台上,而且我自己也不使用 task-bar,所以我无法真正测试它),但尝试摆脱 parent:

class Dialog_02(QtGui.QMainWindow):
    def __init__(self, other_window):
        super(Dialog_02, self).__init__()
        # ensure this window gets garbage-collected when closed
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self._other_window = other_window
    ...    

    def closeAndReturn(self):
        self.close()
        self._other_window.show()