KRichTextEdit

KDE 4.7 PyKDE API Reference

- KDE's Python API

# KRichTextEdit Class Reference

`from PyKDE4.kdeui import *`

Inherits: KTextEdit → QTextEdit → QAbstractScrollArea → QFrame → QWidget → QObject

## Detailed Description

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().

"KDE Rich Text Edit Widget"

Since:
  4.1

## Enumerations
Mode | { Plain, Rich }
## Signals
| selectionFinished ()
| textModeChanged (KRichTextEdit.Mode mode)
## Methods
| __init__ (self, QString text, QWidget parent=0)
| __init__ (self, QWidget parent=0)
| alignCenter (self)
| alignJustify (self)
| alignLeft (self)
| alignRight (self)
bool | canDedentList (self)
bool | canIndentList (self)
QString | currentLinkText (self)
QString | currentLinkUrl (self)
| enableRichTextMode (self)
| indentListLess (self)
| indentListMore (self)
| insertHorizontalRule (self)
| keyPressEvent (self, QKeyEvent event)
| makeLeftToRight (self)
| makeRightToLeft (self)
| selectLinkText (self, QTextCursor cursor)
| selectLinkText (self)
| setFont (self, QFont font)
| setFontFamily (self, QString fontFamily)
| setFontSize (self, int size)
| setListStyle (self, int _styleIndex)
| setTextBackgroundColor (self, QColor color)
| setTextBold (self, bool bold)
| setTextForegroundColor (self, QColor color)
| setTextItalic (self, bool italic)
| setTextOrHtml (self, QString text)
| setTextStrikeOut (self, bool strikeOut)
| setTextSubScript (self, bool subscript)
| setTextSuperScript (self, bool superscript)
| setTextUnderline (self, bool underline)
| switchToPlainText (self)
KRichTextEdit.Mode | textMode (self)
QString | textOrHtml (self)
QString | toCleanHtml (self)
| updateLink (self, QString linkUrl, QString linkText)

## Signal Documentation

selectionFinished | ( |  | ) |

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

Signal syntax:
  `QObject.connect(source, SIGNAL("selectionFinished()"), target_slot)`

textModeChanged | ( | KRichTextEdit.Mode | mode
| ) |  |  |

Emitted whenever the text mode is changed.

Parameters:

  | mode | The new text mode

Signal syntax:
  `QObject.connect(source, SIGNAL("textModeChanged(KRichTextEdit::Mode)"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QString | text,
|  | QWidget | parent=0
| ) |  |  |

Constructs a KRichTextEdit object

Parameters:

  | text | The initial text of the text edit, which is interpreted as HTML.
  | parent | The parent widget

__init__ | ( | self, |
|  | QWidget | parent=0
| ) |  |  |

Constructs a KRichTextEdit object.

Parameters:

  | parent | The parent widget

alignCenter | ( |  | self ) |

Sets the alignment of the current block to Centered

alignJustify | ( |  | self ) |

Sets the alignment of the current block to Justified

alignLeft | ( |  | self ) |

Sets the alignment of the current block to Left Aligned

alignRight | ( |  | self ) |

Sets the alignment of the current block to Right Aligned

bool canDedentList | ( |  | self ) |

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

@sa canIndentList

bool canIndentList | ( |  | self ) |

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

@sa canDedentList

QString currentLinkText | ( |  | self ) |

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

@sa currentLinkUrl

Returns:
  The link text

QString currentLinkUrl | ( |  | self ) |

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

@sa currentLinkText

Returns:
  The link target URL

enableRichTextMode | ( |  | self ) |

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

indentListLess | ( |  | self ) |

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

@sa canDedentList

indentListMore | ( |  | self ) |

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

@sa canIndentList

insertHorizontalRule | ( |  | self ) |

Inserts a horizontal rule below the current block.

keyPressEvent | ( | self, |
|  | QKeyEvent | event
| ) |  |  |

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

makeLeftToRight | ( |  | self ) |

Sets the direction of the current block to Left-To-Right

Since:
  4.6

makeRightToLeft | ( |  | self ) |

Sets the direction of the current block to Right-To-Left

Since:
  4.6

selectLinkText | ( | self, |
|  | QTextCursor | cursor
| ) |  |  |

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

@sa selectLinkText

selectLinkText | ( |  | self ) |

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

@sa selectLinkText

setFont | ( | self, |
|  | QFont | font
| ) |  |  |

Sets the current word or selection to the font font

Parameters:

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

setFontFamily | ( | self, |
|  | QString | fontFamily
| ) |  |  |

Sets the current word or selection to the font family fontFamily

Parameters:

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

setFontSize | ( | self, |
|  | int | size
| ) |  |  |

Sets the current word or selection to the font size size

Parameters:

  | size | The text's font will get this size

setListStyle | ( | self, |
|  | int | _styleIndex
| ) |  |  |

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

Parameters:

  | _styleIndex | The list will get this style

setTextBackgroundColor | ( | self, |
|  | QColor | color
| ) |  |  |

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

Parameters:

  | color | The text will get this foreground color

setTextBold | ( | self, |
|  | bool | bold
| ) |  |  |

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

Parameters:

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

setTextForegroundColor | ( | self, |
|  | QColor | color
| ) |  |  |

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

Parameters:

  | color | The text will get this background color

setTextItalic | ( | self, |
|  | bool | italic
| ) |  |  |

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

Parameters:

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

setTextOrHtml | ( | self, |
|  | QString | text
| ) |  |  |

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.

Parameters:

  | text | The text to insert

setTextStrikeOut | ( | self, |
|  | bool | strikeOut
| ) |  |  |

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

Parameters:

  | strikeOut | If true, the text will be struck out

setTextSubScript | ( | self, |
|  | bool | subscript
| ) |  |  |

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

Parameters:

  | subscript | If true, the text will be set to subscript

setTextSuperScript | ( | self, |
|  | bool | superscript
| ) |  |  |

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

Parameters:

  | superscript | If true, the text will be set to superscript

setTextUnderline | ( | self, |
|  | bool | underline
| ) |  |  |

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

Parameters:

  | underline | If true, the text will be underlined

switchToPlainText | ( |  | self ) |

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

KRichTextEdit.Mode textMode | ( |  | self ) |

Returns:
  The current text mode

QString textOrHtml | ( |  | self ) |

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.

QString toCleanHtml | ( |  | self ) |

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 | ( | self, |
|  | QString | linkUrl,
|  | QString | linkText
| ) |  |  |

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

@sa selectLinkText @sa currentLinkUrl @sa currentLinkText

Parameters:

  | 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.

## Enumeration Documentation

Mode

The mode the edit widget is in.

Enumerator:

  Plain |
  Rich |