使用PySide保持顶部窗口

时间:2016-12-09 17:12:57

标签: python qt pyside

我有一个用Pyside写的应用程序。我想在我的应用程序窗口中使用一个复选框,始终显示在顶部。

class RemoteWindow(QtGui.QMainWindow):
"""
This is the main window for the capacitiveRemote which contains the remote
itself for controlling the boxes and shortcuts to starting scripts.
"""
def __init__(self):
    super(RemoteWindow, self).__init__()
    self.initUI()

这是我的功能

def stayOnTop(self):
    if self.checkBoxTop:
        self.checkBoxTop.setStyleSheet("color: green")
        self.QMainWindow.setWindowFlags(QMainWindow.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)

这是复选框

#Stay on the top Checkboxes 

        self.checkBoxTop = QtGui.QCheckBox('Stay on top', self)
        self.checkBoxTop.setMaximumWidth(90)
        self.checkBoxTop.setChecked(0)
        self.checkBoxTop.clicked.connect(
            lambda: self.stayOnTop(),
        )

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

 def stayOntop(self):

    if self.checkBoxTop:
        self.checkBoxTop.setStyleSheet("color: green")
        self.setWindowFlags(self.windowFlags() ^ QtCore.Qt.WindowStaysOnTopHint)
        self.show()

    else: 
        self.checkBoxTop.setStyleSheet("color: black")
相关问题