From 96be1bd23ffac47d21b6884688f8089d41a181b5 Mon Sep 17 00:00:00 2001 From: 2xB <31772910+2xB@users.noreply.github.com> Date: Mon, 4 May 2020 23:58:29 +0200 Subject: [PATCH] Fix: AxisItem tickFont is defined in two places while only one is used (#1180) To set the tick font of `AxisItem`s, there are two options: `setStyle({"tickFont":...})` and `setTickFont(...)`. The first option sets `AxisItem.style['tickFont']`, the second sets `self.tickFont`. Only `self.tickFont` is actually used. This PR replaces all occurrences of the second variable with the first variable, so both options work again. Also, documentation from `setStyle` is copied to `setTickFont`. Co-authored-by: 2xB <2xB@users.noreply.github.com> --- pyqtgraph/graphicsItems/AxisItem.py | 11 +++++++---- pyqtgraph/graphicsItems/DateAxisItem.py | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pyqtgraph/graphicsItems/AxisItem.py b/pyqtgraph/graphicsItems/AxisItem.py index 3faf83a4..2c6a15e3 100644 --- a/pyqtgraph/graphicsItems/AxisItem.py +++ b/pyqtgraph/graphicsItems/AxisItem.py @@ -82,7 +82,6 @@ class AxisItem(GraphicsWidget): self.labelUnitPrefix = unitPrefix self.labelStyle = args self.logMode = False - self.tickFont = None self._tickLevels = None ## used to override the automatic ticking system with explicit ticks self._tickSpacing = None # used to override default tickSpacing method @@ -205,7 +204,11 @@ class AxisItem(GraphicsWidget): self.update() def setTickFont(self, font): - self.tickFont = font + """ + (QFont or None) Determines the font used for tick values. + Use None for the default font. + """ + self.style['tickFont'] = font self.picture = None self.prepareGeometryChange() ## Need to re-allocate space depending on font size? @@ -1084,8 +1087,8 @@ class AxisItem(GraphicsWidget): profiler('draw ticks') # Draw all text - if self.tickFont is not None: - p.setFont(self.tickFont) + if self.style['tickFont'] is not None: + p.setFont(self.style['tickFont']) p.setPen(self.textPen()) for rect, flags, text in textSpecs: p.drawText(rect, int(flags), text) diff --git a/pyqtgraph/graphicsItems/DateAxisItem.py b/pyqtgraph/graphicsItems/DateAxisItem.py index 9d692dac..7cf9be2c 100644 --- a/pyqtgraph/graphicsItems/DateAxisItem.py +++ b/pyqtgraph/graphicsItems/DateAxisItem.py @@ -308,8 +308,8 @@ class DateAxisItem(AxisItem): # Get font metrics from QPainter # Not happening in "paint", as the QPainter p there is a different one from the one here, # so changing that font could cause unwanted side effects - if self.tickFont is not None: - p.setFont(self.tickFont) + if self.style['tickFont'] is not None: + p.setFont(self.style['tickFont']) self.fontMetrics = p.fontMetrics()