我略微缩小了StyledTextCtrl的字体大小,但它不会影响文本控件边距的字体大小,即行号字体:
有没有办法控制边距中的字体大小?
对于那些感兴趣的人,这是我的子类:
class CustomTextCtrl(StyledTextCtrl):
"""A `StyledTextCtrl` subclass with custom settings."""
def __init__(self, *args, **kwargs):
StyledTextCtrl.__init__(self, *args, **kwargs)
# Set the highlight color to the system highlight color.
highlight_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
self.SetSelBackground(True, highlight_color)
# Set the font to a fixed width font.
font = wx.Font(12, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL, False, 'Consolas',
wx.FONTENCODING_UTF8)
self.StyleSetFont(0, font)
# Enable line numbers.
self.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
self.SetMarginMask(1, 0)
self.SetMarginWidth(1, 25)
def SetText(self, text):
"""Override of the `SetText` function to circumvent readonly."""
readonly = self.GetReadOnly()
self.SetReadOnly(False)
StyledTextCtrl.SetText(self, text)
self.SetReadOnly(readonly)
def ClearAll(self):
"""Override of the `ClearAll` function to circumvent readonly."""
readonly = self.GetReadOnly()
self.SetReadOnly(False)
StyledTextCtrl.ClearAll(self)
self.SetReadOnly(readonly)
答案 0 :(得分:1)
您使用的是StyleSetFont的错误样式编号。您可能打算使用:
self.StyleSetFont(wx.stc.STC_STYLE_DEFAULT,font)
,其值为32而不是0.如果要分别设置行号的字体,请使用:
self.StyleSetFont(wx.stc.STC_STYLE_LINENUMBER,font)