Set line height / vertical margin for wx.StyledTextCtrl

How can I set the amount of line height / vertical margin for wx.StyledTextCtrl. Currently, (it seems by default) if you are on the first line, the caret “hits” the top of the control.

How can I add space to the top so that it doesn’t do that?

Hi,

Unfortunately, there are no methods to set top-margin, neither line-height in stc. For example, some attributes are matching to ‘height’ in stc, but all are read-only properties or getter functions.

    self.ed.AutoCompGetMaxHeight                 <built-in method AutoCompGetMaxHeight of StyledTextCtrl object at 0x000001B065D9...
    self.ed.AutoCompSetMaxHeight                 <built-in method AutoCompSetMaxHeight of StyledTextCtrl object at 0x000001B065D9...
    self.ed.CharHeight                           15
    self.ed.GetBestHeight                        <built-in method GetBestHeight of StyledTextCtrl object at 0x000001B065D99160>
    self.ed.GetCharHeight                        <built-in method GetCharHeight of StyledTextCtrl object at 0x000001B065D99160>
    self.ed.GetMaxHeight                         <built-in method GetMaxHeight of StyledTextCtrl object at 0x000001B065D99160>
    self.ed.GetMinHeight                         <built-in method GetMinHeight of StyledTextCtrl object at 0x000001B065D99160>
    self.ed.MaxHeight                            -1
    self.ed.MinHeight                            -1
    self.ed.RGBAImageSetHeight                   <built-in method RGBAImageSetHeight of StyledTextCtrl object at 0x000001B065D991...
    self.ed.TextHeight                           <built-in method TextHeight of StyledTextCtrl object at 0x000001B065D99160>
... found 11 words.

How about this?

  1. Set the line number size bigger (you should hide the line number margin).
  2. Add paddings around the stc control.
    self.ed = wx.stc.StyledTextCtrl(self, style=wx.NO_BORDER)
    self.ed.StyleClearAll()
    self.ed.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER, 'size:18') 
    
    self.SetSizer(wx.BoxSizer())
    self.Sizer.Add(self.ed, 1, wx.EXPAND|wx.ALL, 8)
    self.SetBackgroundColour('silver')

Clipboard02

Thanks for the answer. I will look into this. :slight_smile: