PyQt5 can't delete flag WindowStaysOnTopHint under Ubuntu 18.04

谁都会走 提交于 2020-03-05 07:31:42

问题


I'm trying to make a button which would place window on top of others. Using recommends from other questions, I put in my class setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) to set and setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint) to delete flag. It sets the flag, but when i change the button state, it still has that flag enabled. Here is code example:

from PyQt5 import QtWidgets, QtCore
import sys

class widget(QtWidgets.QWidget):
    def __init__(self):
        QtWidgets.QWidget.__init__(self)

        self.resize(500, 500)
        box = QtWidgets.QVBoxLayout()
        self.setLayout(box)

        self.btn = QtWidgets.QPushButton("pin")
        box.addWidget(self.btn)
        self.btn.setCheckable(True)
        self.btn.toggled.connect(self.setOnTop)

    def setOnTop(self):
        if self.btn.isChecked():
            self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
            print("checked")
        else:
            self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint)
            print("unchecked")
        self.show()

def main(self):
    app = QtWidgets.QApplication(sys.argv)
    ex = widget()
    ex.show()
    sys.exit(app.exec_())

main()

来源:https://stackoverflow.com/questions/53141178/pyqt5-cant-delete-flag-windowstaysontophint-under-ubuntu-18-04

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