1

我稍微减小了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)
4

1 回答 1

1

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

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

其值为 32 而不是 0。如果要单独设置行号的字体,请使用:

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

有关详细信息,请参阅wxStyledTextCtrl - 样式和样式定义

于 2012-10-25T12:09:36.760 回答