我可以在StyledTextCtrl的边距中控制字体大小吗?

时间:2012-10-25 11:03:11

标签: python wxpython

我略微缩小了StyledTextCtrl的字体大小,但它不会影响文本控件边距的字体大小,即行号字体:

Example

有没有办法控制边距中的字体大小?


对于那些感兴趣的人,这是我的子类:

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)

1 个答案:

答案 0 :(得分:1)

您使用的是StyleSetFont的错误样式编号。您可能打算使用:

self.StyleSetFont(wx.stc.STC_STYLE_DEFAULT,font)

,其值为32而不是0.如果要分别设置行号的字体,请使用:

self.StyleSetFont(wx.stc.STC_STYLE_LINENUMBER,font)

有关详细信息,请参阅wxStyledTextCtrl - Styling & Style Definition