本文介绍了PyQt - 隐藏 MainWindow 并显示 QDialog 而没有任务栏图标消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用此示例中的代码 PyQt:如何隐藏 QMainWindow:
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()
它可以工作,但是当打开第二个窗口时,窗口的任务栏图标不显示.我也尝试将 QtGui.QDialog 用于 Dialog_02,但这给了我相同的结果.
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?
我使用的是 Windows 10
I'm on Windows 10
推荐答案
只是猜测(因为我不知道你在什么平台上,而且我自己不使用任务栏,所以我无法真正测试它),但尝试摆脱父母:
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()
这篇关于PyQt - 隐藏 MainWindow 并显示 QDialog 而没有任务栏图标消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!