1

我有一个 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)
4

1 回答 1

5

setWindowFlags的文档中:

注意:此函数在更改窗口的标志时调用 setParent(),导致窗口小部件被隐藏。您必须调用 show() 使小部件再次可见。

于 2013-11-02T01:43:39.097 回答