Merge pull request #1257 from VesnaT/tickFont_painter

AxisItem: Make painter (tick) font dependent
This commit is contained in:
Ogi Moore 2020-06-15 07:54:25 -07:00 committed by GitHub
commit 0c08adc411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -576,6 +576,8 @@ class AxisItem(GraphicsWidget):
try: try:
picture = QtGui.QPicture() picture = QtGui.QPicture()
painter = QtGui.QPainter(picture) painter = QtGui.QPainter(picture)
if self.style["tickFont"]:
painter.setFont(self.style["tickFont"])
specs = self.generateDrawSpecs(painter) specs = self.generateDrawSpecs(painter)
profiler('generate specs') profiler('generate specs')
if specs is not None: if specs is not None:

View File

@ -87,3 +87,30 @@ def test_AxisItem_leftRelink():
assert fake_view.sigYRangeChanged.calls == ['connect', 'disconnect'] assert fake_view.sigYRangeChanged.calls == ['connect', 'disconnect']
assert fake_view.sigXRangeChanged.calls == [] assert fake_view.sigXRangeChanged.calls == []
assert fake_view.sigResized.calls == ['connect', 'disconnect'] assert fake_view.sigResized.calls == ['connect', 'disconnect']
def test_AxisItem_tickFont(monkeypatch):
def collides(textSpecs):
fontMetrics = pg.Qt.QtGui.QFontMetrics(font)
for rect, _, text in textSpecs:
br = fontMetrics.tightBoundingRect(text)
if rect.height() < br.height() or rect.width() < br.width():
return True
return False
def test_collision(p, axisSpec, tickSpecs, textSpecs):
assert not collides(textSpecs)
plot = pg.PlotWidget()
bottom = plot.getAxis("bottom")
left = plot.getAxis("left")
font = bottom.linkedView().font()
font.setPointSize(25)
bottom.setStyle(tickFont=font)
left.setStyle(tickFont=font)
monkeypatch.setattr(bottom, "drawPicture", test_collision)
monkeypatch.setattr(left, "drawPicture", test_collision)
plot.show()
app.processEvents()
plot.close()