如何在pyqtgraph中定义码头的图标?

发布于 2025-02-02 14:27:04 字数 736 浏览 4 评论 0原文

在pyqtgraph中,可以通过拖动或双击从码头上撕下码头。弹出窗口使用默认图标。我想定义自己的图标。在下面的代码中,我设置了应用程序窗口。尽管没有错误消息,但相同的代码对码头没有影响。

import sys
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout
from pyqtgraph.dockarea import Dock, DockArea
from PyQt5.QtGui import QIcon

class Foo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)        
        self.setWindowIcon(QIcon('direction'))
        lay = QVBoxLayout(self)        
        da = DockArea()
        d = Dock("Dock")
        d.setWindowIcon(QIcon('direction')) # no effect
        da.addDock(d)
        lay.addWidget(da)
        
if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = Foo()
    w.show()
    sys.exit(app.exec_())

In pyqtgraph, Docks can be torn out of the DockArea by dragging or double clicking. The popups use a default icon. I would like to define my own icon. In the code below I set the application window. The same code has no effect on the dock, though there is no error message.

import sys
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout
from pyqtgraph.dockarea import Dock, DockArea
from PyQt5.QtGui import QIcon

class Foo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)        
        self.setWindowIcon(QIcon('direction'))
        lay = QVBoxLayout(self)        
        da = DockArea()
        d = Dock("Dock")
        d.setWindowIcon(QIcon('direction')) # no effect
        da.addDock(d)
        lay.addWidget(da)
        
if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = Foo()
    w.show()
    sys.exit(app.exec_())

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

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

发布评论

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

评论(1

伤感在游骋 2025-02-09 14:27:05

我查看了Pyqtgraph的Dock和Dockarea的源代码,发现我必须覆盖 floatdock 函数。

我创建了一个函数

def floatDockPatched(self, dock):
    """Removes *dock* from this DockArea and places it in a new window."""
    area = self.addTempArea()
    area.win.resize(dock.size())
    area.win.setWindowIcon(QIcon("res/haip.png"))
    area.win.setWindowTitle(dock.label.text())
    area.moveDock(dock, 'top', None)

,并将其分配给类,作为覆盖

DockArea.floatDock = floatDockPatched

I looked in the source code of Dock and DockArea of pyqtgraph and found out I had to overwrite floatDock function.

I created a function

def floatDockPatched(self, dock):
    """Removes *dock* from this DockArea and places it in a new window."""
    area = self.addTempArea()
    area.win.resize(dock.size())
    area.win.setWindowIcon(QIcon("res/haip.png"))
    area.win.setWindowTitle(dock.label.text())
    area.moveDock(dock, 'top', None)

and assigned it to the class as overwrite

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