From f67e4cf06b7a20e4836ac5805e83c909fdad631c Mon Sep 17 00:00:00 2001 From: Ardi Loot Date: Wed, 27 Apr 2022 11:20:22 +0300 Subject: [PATCH] Added possibility to use custom dock labels --- pyqtgraph/dockarea/Dock.py | 18 ++++++++++++------ pyqtgraph/dockarea/__init__.py | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pyqtgraph/dockarea/Dock.py b/pyqtgraph/dockarea/Dock.py index 0e6ee875ef..fb73fa1d8b 100644 --- a/pyqtgraph/dockarea/Dock.py +++ b/pyqtgraph/dockarea/Dock.py @@ -10,14 +10,17 @@ class Dock(QtWidgets.QWidget, DockDrop): sigStretchChanged = QtCore.Signal() sigClosed = QtCore.Signal(object) - def __init__(self, name, area=None, size=(10, 10), widget=None, hideTitle=False, autoOrientation=True, closable=False, fontSize="12px"): + def __init__(self, name, area=None, size=(10, 10), widget=None, hideTitle=False, autoOrientation=True, label=None, **kargs): QtWidgets.QWidget.__init__(self) DockDrop.__init__(self) self._container = None self._name = name self.area = area - self.label = DockLabel(name, self, closable, fontSize) - if closable: + self.label = label + if self.label is None: + self.label = DockLabel(name, **kargs) + self.label.dock = self + if self.label.isClosable(): self.label.sigCloseClicked.connect(self.close) self.labelHidden = False self.moveLabel = True ## If false, the dock is no longer allowed to move the label. @@ -262,19 +265,19 @@ class DockLabel(VerticalLabel): sigClicked = QtCore.Signal(object, object) sigCloseClicked = QtCore.Signal() - def __init__(self, text, dock, showCloseButton, fontSize): + def __init__(self, text, closable=False, fontSize="12px"): self.dim = False self.fixedWidth = False self.fontSize = fontSize VerticalLabel.__init__(self, text, orientation='horizontal', forceWidth=False) self.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop|QtCore.Qt.AlignmentFlag.AlignHCenter) - self.dock = dock + self.dock = None self.updateStyle() self.setAutoFillBackground(False) self.mouseMoved = False self.closeButton = None - if showCloseButton: + if closable: self.closeButton = QtWidgets.QToolButton(self) self.closeButton.clicked.connect(self.sigCloseClicked) self.closeButton.setIcon(QtWidgets.QApplication.style().standardIcon(QtWidgets.QStyle.StandardPixmap.SP_TitleBarCloseButton)) @@ -330,6 +333,9 @@ def setOrientation(self, o): VerticalLabel.setOrientation(self, o) self.updateStyle() + def isClosable(self): + return self.closeButton is not None + def mousePressEvent(self, ev): lpos = ev.position() if hasattr(ev, 'position') else ev.localPos() self.pressPos = lpos diff --git a/pyqtgraph/dockarea/__init__.py b/pyqtgraph/dockarea/__init__.py index 3fa96f04e3..c3ff83b6df 100644 --- a/pyqtgraph/dockarea/__init__.py +++ b/pyqtgraph/dockarea/__init__.py @@ -1,2 +1,2 @@ -from .Dock import Dock +from .Dock import Dock, DockLabel from .DockArea import DockArea