【问题标题】:Stay window on the top with PySide使用 PySide 将窗口保持在顶部
【发布时间】:2016-12-13 00:30:40
【问题描述】:

我有一个用 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(),
        )

任何帮助将不胜感激。

【问题讨论】:

标签: python qt pyside


【解决方案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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-08
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多