# class KRichTextEdit

###

Module | kdeui
Namespace |
Class | KRichTextEdit
Inherits | KTextEdit

The KRichTextEdit class provides a widget to edit and display rich text.

It offers several additional rich text editing functions to KTextEdit and makes them easier to access including:

- Changing fonts, sizes.
- Font formatting, such as bold, underline, italic, foreground and
background color.
- Paragraph alignment
- Ability to edit and remove hyperlinks
- Nested list handling
- Simple actions to insert tables. TODO

The KRichTextEdit can be in two modes: Rich text mode and plain text mode. Calling functions which modify the format/style of the text will automatically enable the rich text mode. Rich text mode is sometimes also referred to as HTML mode.

Do not call setAcceptRichText() or acceptRichText() yourself. Instead simply connect to the slots which insert the rich text, use switchToPlainText() or enableRichTextMode().

@since 4.1

### enums

- Mode { Plain, Rich }

enum details

### methods

- KRichTextEdit (text, parent)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  text | QString |
  parent | QWidget | 0

  Constructs a KRichTextEdit object

  text - The initial text of the text edit, which is interpreted as HTML.

  parent - The parent widget

- KRichTextEdit (parent)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  parent | QWidget | 0

  Constructs a KRichTextEdit object.

  parent - The parent widget

- alignCenter ( )

  returns Nothing

  Sets the alignment of the current block to Centered

- alignJustify ( )

  returns Nothing

  Sets the alignment of the current block to Justified

- alignLeft ( )

  returns Nothing

  Sets the alignment of the current block to Left Aligned

- alignRight ( )

  returns Nothing

  Sets the alignment of the current block to Right Aligned

- canDedentList ( )

  returns bool

  Returns true if the list item at the current position can be dedented.

  See also canIndentList

- canIndentList ( )

  returns bool

  Returns true if the list item at the current position can be indented.

  See also canDedentList

- currentLinkText ( )

  returns QString

  Returns the text of the link at the current position or an empty string if the cursor is not on a link.

  See also currentLinkUrl Returns The link text

- currentLinkUrl ( )

  returns QString

  Returns the URL target (href) of the link at the current position or an empty string if the cursor is not on a link.

  See also currentLinkText Returns The link target URL

- enableRichTextMode ( )

  returns Nothing

  This enables rich text mode. Nothing is done except changing the internal mode and allowing rich text pastes.

- indentListLess ( )

  returns Nothing

  Decreases the nesting level of the current block or selected blocks.

  See also canDedentList

- indentListMore ( )

  returns Nothing

  Increases the nesting level of the current block or selected blocks.

  See also canIndentList

- insertHorizontalRule ( )

  returns Nothing

  Inserts a horizontal rule below the current block.

- keyPressEvent (event)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  event | QKeyEvent |

  Reimplemented. Catches key press events. Used to handle some key presses on lists.

- selectLinkText (cursor)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  cursor | QTextCursor |

  If the cursor is on a link, sets the cursor to a selection of the text of the link. If the cursor is not on a link, selects the current word or existing selection.

  cursor - The cursor to use to select the text.

  See also updateLink

- selectLinkText ( )

  returns Nothing

  Convenience function to select the link text using the active cursor.

  See also selectLinkText

- selectionFinished ( )

  returns Nothing
  SIGNAL ("selectionFinished ()")

  Emitted whenever the user has finished making a selection. (on mouse up)

- setFont (font)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  font | QFont |

  Sets the current word or selection to the font font

  font - the font of the text will be set to this font

- setFontFamily (fontFamily)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  fontFamily | QString |

  Sets the current word or selection to the font family fontFamily

  fontFamily - The text's font family will be changed to this one

- setFontSize (size)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  size | int |

  Sets the current word or selection to the font size size

  size - The text's font will get this size

- setListStyle (_styleIndex)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _styleIndex | int |

  Sets the list style of the current list, or creates a new list using the current block. The _styleindex corresponds to the QTextListFormat.Style

  _styleIndex - The list will get this style

- setTextBackgroundColor (color)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  color | QColor |

  Sets the background color of the current word or selection to color.

  color - The text will get this foreground color

- setTextBold (bold)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  bold | bool |

  Toggles the bold formatting of the current word or selection at the current cursor position.

  bold - If true, the text will be set to bold

- setTextForegroundColor (color)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  color | QColor |

  Sets the foreground color of the current word or selection to color.

  color - The text will get this background color

- setTextItalic (italic)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  italic | bool |

  Toggles the italic formatting of the current word or selection at the current cursor position.

  italic - If true, the text will be set to italic

- setTextOrHtml (text)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  text | QString |

  Replaces all the content of the text edit with the given string. If the string is in rich text format, the text is inserted as rich text, otherwise it is inserted as plain text.

  text - The text to insert

- setTextStrikeOut (strikeOut)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  strikeOut | bool |

  Toggles the strikeout formatting of the current word or selection at the current cursor position.

  strikeOut - If true, the text will be struck out

- setTextUnderline (underline)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  underline | bool |

  Toggles the underline formatting of the current word or selection at the current cursor position.

  underline - If true, the text will be underlined

- switchToPlainText ( )

  returns Nothing

  This will switch the editor to plain text mode. All rich text formatting will be destroyed.

- textMode ( )

  returns KRichTextEdit.Mode

  Returns The current text mode

- textModeChanged (mode)

  returns Nothing
  SIGNAL ("textModeChanged (Mode)")

  Argument | Type | Default
  --- | --- | ---
  mode | KRichTextEdit.Mode |

  Emitted whenever the text mode is changed.

  mode - The new text mode

- textOrHtml ( )

  returns QString

  Returns The plain text string if in plain text mode or the HTML code if in rich text mode. The text is not word-wrapped.

- toCleanHtml ( )

  returns QString

  This will clean some of the bad html produced by the underlying QTextEdit It walks over all lines and cleans up a bit. Should be improved to produce our own Html.

- updateLink (linkUrl, linkText)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  linkUrl | QString |
  linkText | QString |

  Replaces the current selection with a hyperlink with the link URL linkUrl and the link text linkText.

  See also selectLinkText

  See also currentLinkUrl

  See also currentLinkText

  linkUrl - The link will get this URL as href (target)

  linkText - The link will get this alternative text, which is the text displayed in the text edit.

### enums - detail

- Mode { Plain, Rich }

  The mode the edit widget is in.

  | Plain | - | - |
  | Rich | - | - |