【问题标题】:PyQt4: how to make undercorated window with reserved spacePyQt4:如何使用保留空间制作undercorated窗口
【发布时间】:2011-04-29 08:07:33
【问题描述】:

我想使用 PyQt4 for Linux 制作一个类似面板的应用程序。为此我需要我创建的窗口:

  • 未装饰
  • 预留空间
  • 出现在所有工作区

通过阅读the documentation,我知道我应该使用 QtWindowFlags。但我不知道如何做到这一点。另外我相信应该有一个 Qt.WindowType 提示告诉 WM 窗口是一个“停靠”应用程序。我在this thread 之后用pygtk 做了这个,但是用Qt 我真的不知道如何处理这个。 (我需要 Qt,因为它能够更轻松地主题/皮肤应用程序。)

下面是我当前编写的代码(没什么特别的)。

import sys
from PyQt4 import QtGui

class Panel(QtGui.QWidget):
def __init__(self, parent=None): ## should the QtWindowFlag be here?
    QtGui.QWidget.__init__(self, parent) ## should the QtWindowFlag be there as well?

    self.setWindowTitle('QtPanel')
    self.resize(QtGui.QDesktopWidget().screenGeometry().width(), 25)
    self.move(0,0)

def main():
    app = QtGui.QApplication(sys.argv)
    panel = Panel()
    panel.show()
    sys.exit(app.exec_())
    return 0

if __name__ == '__main__':
    main()

谁能帮我解决这个问题?谢谢:)

【问题讨论】:

    标签: python pyqt4 flags overlap borderless


    【解决方案1】:

    了解 QWidget.windowFlags 属性:http://doc.qt.nokia.com/4.7/qwidget.html#windowFlags-prop

    例子:

    >>> from PyQt4 import QtGui, QtCore
    >>> app = QtGui.QApplication([])
    >>> win = QtGui.QMainWindow()
    >>> win.setWindowFlags(win.windowFlags() | QtCore.Qt.FramelessWindowHint)
    >>> win.show()
    

    【讨论】:

    • 谢谢。我没有在 Qt4 文档中找到任何标志来保留屏幕上的空间。谷歌也不提供任何提示。 (也许我没有很好地制定它?)
    • 我没有看到任何关于 Qt 中保留空间或工作区的信息。您可能需要直接访问您的窗口管理器。
    • 这就是我所担心的,所以我已经改写了the question for general purpose。还是谢谢。
    【解决方案2】:
    import sys
    from PyQt4 import QtGui, QtCore
    
    
    class Example(QtGui.QWidget):
    
        def __init__(self):
            super(Example, self).__init__()
    
            self.initUI()
    
        def initUI(self):               
    
            qbtn = QtGui.QPushButton('Quit', self)
            #qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
            qbtn.clicked.connect(self.test)
            qbtn.resize(qbtn.sizeHint())
            qbtn.move(50, 50)       
    
            self.setGeometry(300, 300, 250, 150)
            self.setWindowTitle('Quit button')    
            self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
            self.show()
    
        def test(self):
          print "test"
    
    def main():
    
        app = QtGui.QApplication(sys.argv)
        ex = Example()
        sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
        main()
    

    【讨论】:

      【解决方案3】:

      解决方法是使用Python-Xlib,在an answer on a universal way to reserve screen space on X中有描述。

      【讨论】:

        猜你喜欢
        • 2018-08-09
        • 2023-04-03
        • 2021-05-29
        • 1970-01-01
        • 2018-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多