Skip to content

Commit

Permalink
Merge pull request pyqtgraph#2274 from ardiloot/custom-dock-label
Browse files Browse the repository at this point in the history
Added possibility to use custom dock labels
  • Loading branch information
j9ac9k authored Apr 28, 2022
2 parents a6aa780 + f67e4cf commit 6f6e86e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions pyqtgraph/dockarea/Dock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyqtgraph/dockarea/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .Dock import Dock
from .Dock import Dock, DockLabel
from .DockArea import DockArea

0 comments on commit 6f6e86e

Please sign in to comment.