我有一个QWebView对象,我设置了 WindowStaysOnTopHint ,但是当我关闭它时,QWebView对象就消失了。
view = QWebView()
view.setWindowFlags(WindowStaysOnTopHint)
view.show()
....
#in some slot
view.setWindowFlags(WindowStaysBottomHint) # causes window to disappear
更新
之前的设置是代码的简化版本,以下是更多详细信息。
class Window(QObject):
self.view = QWebView()
self.view.setWindowFlags(WindowStayOnTopHint)
self.installEventFilter(this)
....
def eventFilter(self,qobject, qevent):
if qevent.type() == QEvent.FocusOut:
# Turn on CloseButtonHint and turn off StayOnTopHint
self.view.setWindowFlags(Qt.WindowCloseButtonHint)
qobject.show() # previously I had self.view.show(), does not cause window to show
return super(FeedbackWindow, self).eventFilter(qobject, qevent)
答案 0 :(得分:2)
来自setWindowFlags的文档:
注意:此函数在更改a的标志时调用setParent() 窗口,导致窗口小部件被隐藏。你必须调用show()来制作 小部件再次可见。