PyQt4:如何制作带有保留空间的带装饰的窗口

发布于 2024-11-03 21:03:06 字数 1099 浏览 0 评论 0原文

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

  • 未装饰
  • 以保留空间
  • 以显示在所有工作区上

从阅读 文档 我认为我应该使用 QtWindowFlags。但我不知道如何做到这一点。另外我相信应该有一个 Qt.WindowType 提示告诉 WM 窗口是一个“dock”应用程序。我已经按照 这个线程 用 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()

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

I'd like to make a panel-like application using PyQt4 for Linux. for this i need the window i created:

  • to be undecorated
  • to have reserved space
  • to appear on all workspaces

From reading the documentation i've got the idea that i should use QtWindowFlags. But i have no clue as to how to do that. Also i believe there should be a Qt.WindowType hint somewhere telling the WM the window's a "dock" application. I have made this with pygtk following this thread, but here with Qt i don't really know how to handle this. (I need Qt for its ability to theme/skin application more easily.)

Below is the current code i made (nothing extraordinary).

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()

Can anyone help me with this? Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

大海や 2024-11-10 21:03:06

了解 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()

Read about the QWidget.windowFlags property: http://doc.qt.nokia.com/4.7/qwidget.html#windowFlags-prop

Example:

>>> from PyQt4 import QtGui, QtCore
>>> app = QtGui.QApplication([])
>>> win = QtGui.QMainWindow()
>>> win.setWindowFlags(win.windowFlags() | QtCore.Qt.FramelessWindowHint)
>>> win.show()
一绘本一梦想 2024-11-10 21:03:06
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()
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()
幸福丶如此 2024-11-10 21:03:06

解决方案是使用Python-Xlib,它已在 关于在 X 上保留屏幕空间的通用方法的答案

The solution is to use Python-Xlib, and it has been described in an answer on a universal way to reserve screen space on X.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文