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

空扰寡人 提交于 2019-12-25 09:02:13

问题


I've been using the code from this example 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()

It works, however when opening a second window, the window's task bar icon doesn't show. I've tried using QtGui.QDialog for the Dialog_02 as well but that gives me the same result.

How do I go about solving this?

Edit: I'm on Windows 10


回答1:


Just guessing (because I don't know what platform you're on, and I don't use a task-bar myself, so I cant really test it), but try getting rid of the 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()


来源:https://stackoverflow.com/questions/38739009/pyqt-hide-mainwindow-and-show-qdialog-without-the-taskbar-icon-disappearing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!