Skip to content

TextEditMixin

Sub classes

Name Children Inherits
TextEdit
prettyqt.widgets.textedit
Widget that is used to edit and display both plain and rich text.
TextBrowser
prettyqt.widgets.textbrowser
Rich text browser with hypertext navigation.

    Base classes

    Name Children Inherits
    AbstractScrollAreaMixin
    prettyqt.widgets.abstractscrollarea
    object
    builtins
    The base class of the class hierarchy.
    • type
    • async_generator
    • bytearray_iterator
    • bytearray
    • bytes_iterator
    • bytes
    • builtin_function_or_method
    • callable_iterator
    • PyCapsule
    • cell
    • classmethod_descriptor
    • ...

      â‹” Inheritance diagram

      graph TD
        1964080816["widgets.TextEditMixin"]
        1259044718["widgets.AbstractScrollAreaMixin"]
        1689631995["widgets.FrameMixin"]
        829357528["widgets.WidgetMixin"]
        3227531497["core.ObjectMixin"]
        2751680898["builtins.object"]
        625385617["gui.PaintDeviceMixin"]
        1259044718 --> 1964080816
        1689631995 --> 1259044718
        829357528 --> 1689631995
        3227531497 --> 829357528
        2751680898 --> 3227531497
        625385617 --> 829357528
        2751680898 --> 625385617
        2751680898 --> 829357528
        2751680898 --> 1689631995
        2751680898 --> 1259044718
        2751680898 --> 1964080816

      🛈 DocStrings

      Bases: AbstractScrollAreaMixin, _TextEditBase

      Source code in prettyqt/widgets/textedit.py
      class TextEditMixin(widgets.AbstractScrollAreaMixin, _TextEditBase):
          value_changed = core.Signal(str)
      
          def __init__(self, *args, **kwargs) -> None:
              super().__init__(*args, **kwargs)
              self.textChanged.connect(self.on_value_change)
              self.selecter = texteditselecter.TextEditSelecter(self)
      
          def __add__(self, other: str) -> Self:
              self.append_text(other)
              return self
      
          def _get_map(self):
              maps = super()._get_map()
              maps |= {
                  "autoFormatting": AUTO_FORMATTING,
                  "lineWrapMode": LINE_WRAP_MODE,
                  "wordWrapMode": gui.textoption.WORD_WRAP_MODE,
              }
              return maps
      
          def on_value_change(self) -> None:
              self.value_changed.emit(self.text())
      
          def set_text(self, text: str) -> None:
              self.setPlainText(text)
      
          def append_text(
              self,
              text: str,
              newline: bool = True,
              ensure_visible: Literal["always", "when_bottom", "never"] = "always",
          ):
              scrollbar = self.verticalScrollBar()
              at_bottom = scrollbar.value() >= (scrollbar.maximum() - 4)
              prev_val = scrollbar.value()
              if newline:
                  self.append(text)
              else:
                  self.selecter.move_cursor("end")
                  self.insertHtml(text)
                  self.selecter.move_cursor("end")
              match ensure_visible:
                  case "always":
                      self.ensureCursorVisible()
                  case "when_bottom":
                      if at_bottom:
                          self.ensureCursorVisible()
                  case "never":
                      scrollbar.setValue(prev_val)
      
          def text(self) -> str:
              return self.toPlainText()
      
          def set_read_only(self, value: bool = True) -> None:
              self.setReadOnly(value)
      
          def set_text_color(self, color: datatypes.ColorType) -> None:
              color = colors.get_color(color)
              self.setTextColor(color)
      
          def set_line_wrap_mode(self, mode: LineWrapModeStr | widgets.QTextEdit.LineWrapMode):
              """Set line wrap mode.
      
              Args:
                  mode: line wrap mode to use
              """
              self.setLineWrapMode(LINE_WRAP_MODE.get_enum_value(mode))
      
          def get_line_wrap_mode(self) -> LineWrapModeStr:
              """Get the current wrap mode.
      
              Returns:
                  Wrap mode
              """
              return LINE_WRAP_MODE.inverse[self.lineWrapMode()]
      
          def set_auto_formatting(
              self, mode: AutoFormattingStr | widgets.QTextEdit.AutoFormattingFlag
          ):
              """Set auto formatting mode.
      
              Args:
                  mode: auto formatting mode to use
              """
              self.setAutoFormatting(AUTO_FORMATTING.get_enum_value(mode))
      
          def get_auto_formatting(self) -> AutoFormattingStr:
              """Get the current auto formatting mode.
      
              Returns:
                  Auto formatting mode
              """
              return AUTO_FORMATTING.inverse[self.autoFormatting()]
      
          def set_word_wrap_mode(
              self, mode: gui.textoption.WordWrapModeStr | gui.QTextOption.WrapMode
          ):
              """Set word wrap mode.
      
              Args:
                  mode: word wrap mode to use
              """
              self.setWordWrapMode(gui.textoption.WORD_WRAP_MODE.get_enum_value(mode))
      
          def get_word_wrap_mode(self) -> gui.textoption.WordWrapModeStr:
              """Get the current word wrap mode.
      
              Returns:
                  Word wrap mode
              """
              return gui.textoption.WORD_WRAP_MODE.inverse[self.wordWrapMode()]
      

      get_auto_formatting() -> AutoFormattingStr

      Get the current auto formatting mode.

      Source code in prettyqt/widgets/textedit.py
      def get_auto_formatting(self) -> AutoFormattingStr:
          """Get the current auto formatting mode.
      
          Returns:
              Auto formatting mode
          """
          return AUTO_FORMATTING.inverse[self.autoFormatting()]
      

      get_line_wrap_mode() -> LineWrapModeStr

      Get the current wrap mode.

      Source code in prettyqt/widgets/textedit.py
      def get_line_wrap_mode(self) -> LineWrapModeStr:
          """Get the current wrap mode.
      
          Returns:
              Wrap mode
          """
          return LINE_WRAP_MODE.inverse[self.lineWrapMode()]
      

      get_word_wrap_mode() -> gui.textoption.WordWrapModeStr

      Get the current word wrap mode.

      Source code in prettyqt/widgets/textedit.py
      def get_word_wrap_mode(self) -> gui.textoption.WordWrapModeStr:
          """Get the current word wrap mode.
      
          Returns:
              Word wrap mode
          """
          return gui.textoption.WORD_WRAP_MODE.inverse[self.wordWrapMode()]
      

      set_auto_formatting(mode: AutoFormattingStr | widgets.QTextEdit.AutoFormattingFlag)

      Set auto formatting mode.

      Parameters:

      Name Type Description Default
      mode AutoFormattingStr | AutoFormattingFlag

      auto formatting mode to use

      required
      Source code in prettyqt/widgets/textedit.py
      def set_auto_formatting(
          self, mode: AutoFormattingStr | widgets.QTextEdit.AutoFormattingFlag
      ):
          """Set auto formatting mode.
      
          Args:
              mode: auto formatting mode to use
          """
          self.setAutoFormatting(AUTO_FORMATTING.get_enum_value(mode))
      

      set_line_wrap_mode(mode: LineWrapModeStr | widgets.QTextEdit.LineWrapMode)

      Set line wrap mode.

      Parameters:

      Name Type Description Default
      mode LineWrapModeStr | LineWrapMode

      line wrap mode to use

      required
      Source code in prettyqt/widgets/textedit.py
      def set_line_wrap_mode(self, mode: LineWrapModeStr | widgets.QTextEdit.LineWrapMode):
          """Set line wrap mode.
      
          Args:
              mode: line wrap mode to use
          """
          self.setLineWrapMode(LINE_WRAP_MODE.get_enum_value(mode))
      

      set_word_wrap_mode(mode: gui.textoption.WordWrapModeStr | gui.QTextOption.WrapMode)

      Set word wrap mode.

      Parameters:

      Name Type Description Default
      mode WordWrapModeStr | WrapMode

      word wrap mode to use

      required
      Source code in prettyqt/widgets/textedit.py
      def set_word_wrap_mode(
          self, mode: gui.textoption.WordWrapModeStr | gui.QTextOption.WrapMode
      ):
          """Set word wrap mode.
      
          Args:
              mode: word wrap mode to use
          """
          self.setWordWrapMode(gui.textoption.WORD_WRAP_MODE.get_enum_value(mode))
      

      :fa-brands-github: Show source on GitHub