vtkLegendBoxActor 不支持设置文本字体大小

问题描述 投票:0回答:1

我正在使用 vtkLegendBoxActor 在情节中显示图例。但是,我无法控制图例中文本的字体大小。 我尝试了以下方法:

legendActor=vtkLegendBoxActor()
textProp=vtkTextProperty()
textProp.SetFontSize(3)
textProp.SetVerticalJustificationToCentered()
legendActor.SetEntryTextProperty(textProp)

不过,这个好像没有设置文字的字体大小。它仍然显示默认大小12。我在将属性设置为后检查了字体大小:

legendActor.GetEntryTextProperty().GetFontSize()

返回 3。请帮我解决这个问题。

谢谢。

python vtk
1个回答
0
投票

一个原因可能是

vtkLegendBoxActor
出于性能原因缓存文本属性。所以需要在设置text属性后调用方法
Modified()
使缓存失效

legendActor = vtkLegendBoxActor()
textProp = vtkTextProperty()
textProp.SetFontSize(3)
textProp.SetVerticalJustificationToCentered()
legendActor.SetEntryTextProperty(textProp)
legendActor.Modified()  # Invalidate the cache
© www.soinside.com 2019 - 2024. All rights reserved.