KDE 4.5 PyKDE API Reference

- KDE's Python API

# KRichTextWidget Class Reference

`from PyKDE4.kdeui import *`

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

## Detailed Description

A KRichTextEdit with common actions

This class implements common actions which are often used with KRichTextEdit. All you need to do is to call createActions(), and the actions will be added to your KXMLGUIWindow. Remember to also add the chosen actions to your application ui.rc file.

See the KRichTextWidget.RichTextSupportValues enum for an overview of supported actions.

Author:
  Stephen Kelly <steveire@gmail.com>

Author:
  Thomas McGuire <thomas.mcguire@gmx.net>

"KDE Rich Text Widget"

Since:
  4.1

## Enumerations
RichTextSupportValues | { DisableRichText, SupportBold, SupportItalic, SupportUnderline, SupportStrikeOut, SupportFontFamily, SupportFontSize, SupportTextForegroundColor, SupportTextBackgroundColor, FullTextFormattingSupport, SupportChangeListStyle, SupportIndentLists, SupportDedentLists, FullListSupport, SupportAlignment, SupportRuleLine, SupportHyperlinks, SupportFormatPainting, SupportToPlainText, SupportSuperScriptAndSubScript, FullSupport }
## Methods
| __init__ (self, QWidget parent)
| __init__ (self, QString text, QWidget parent=0)
| createActions (self, KActionCollection actionCollection)
| mouseReleaseEvent (self, QMouseEvent event)
KRichTextWidget.RichTextSupport | richTextSupport (self)
| setActionsEnabled (self, bool enabled)
| setRichTextSupport (self, KRichTextWidget.RichTextSupport support)
| updateActionStates (self)

## Method Documentation

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

Constructor

Parameters:

  | parent | the parent widget

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

Constructs a KRichTextWidget object

Parameters:

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

createActions | ( | self, |
|  | KActionCollection | actionCollection
| ) |  |  |

Creates the actions and adds them to the given action collection.

Call this before calling setupGUI() in your application, but after calling setRichTextSupport().

The XML file of your KXmlGuiWindow needs to have the action names in them, so that the actions actually appear in the menu and in the toolbars.

Below is a list of actions that are created,depending on the supported rich text subset set by setRichTextSupport(). The list contains action names. Those names need to be the same in your XML file.

See the KRichTextWidget.RichTextSupportValues enum documentation for a detailed explaination of each action.

<table> <tr><td>XML Name</td><td>RichTextSupportValues flag</td></tr> <tr><td>format_text_foreground_color</td><td>SupportTextForegroundColor</td></tr> <tr><td>format_text_background_color</td><td>SupportTextBackgroundColor</td></tr> <tr><td>format_font_family</td><td>SupportFontFamily</td></tr> <tr><td>format_font_size</td><td>SupportFontSize</td></tr> <tr><td>format_text_bold</td><td>SupportBold</td></tr> <tr><td>format_text_italic</td><td>SupportItalic</td></tr> <tr><td>format_text_underline</td><td>SupportUnderline</td></tr> <tr><td>format_text_strikeout</td><td>SupportStrikeOut</td></tr> <tr><td>format_align_left</td><td>SupportAlignment</td></tr> <tr><td>format_align_center</td><td>SupportAlignment</td></tr> <tr><td>format_align_right</td><td>SupportAlignment</td></tr> <tr><td>format_align_justify</td><td>SupportAlignment</td></tr> <tr><td>format_list_style</td><td>SupportChangeListStyle</td></tr> <tr><td>format_list_indent_more</td><td>SupportIndentLists</td></tr> <tr><td>format_list_indent_less</td><td>SupportDedentLists</td></tr> <tr><td>insert_horizontal_rule</td><td>SupportRuleLine</td></tr> <tr><td>manage_link</td><td>SupportHyperlinks</td></tr> <tr><td>format_painter</td><td>SupportFormatPainting</td></tr> <tr><td>action_to_plain_text</td><td>SupportToPlainText</td></tr> <tr><td>format_text_subscript & format_text_superscript</td><td>SupportSuperScriptAndSubScript</td></tr> </table>

Parameters:

  | actionCollection | the actions will be added to this action collection

mouseReleaseEvent | ( | self, |
|  | QMouseEvent | event
| ) |  |  |

Reimplemented. Catches mouse release events. Used to know when a selection has been completed.

KRichTextWidget.RichTextSupport richTextSupport | ( |  | self ) |

Returns the supported rich text subset available.

Returns:
  The supported subset.

setActionsEnabled | ( | self, |
|  | bool | enabled
| ) |  |  |

Disables or enables all of the actions created by createActions(). This may be useful in cases where rich text mode may be set on or off.

Parameters:

  | enabled | Whether to enable or disable the actions.

setRichTextSupport | ( | self, |
|  | KRichTextWidget.RichTextSupport | support
| ) |  |  |

Sets the supported rich text subset available.

The default is KRichTextWidget.FullSupport and will be set in the constructor.

You need to call createActions() afterwards.

Parameters:

  | support | The supported subset.

updateActionStates | ( |  | self ) |

Tells KRichTextWidget to update the state of the actions created by createActions(). This is normally automatically done, but there might be a few cases where you'll need to manually call this function.

Call this function only after calling createActions().

## Enumeration Documentation

RichTextSupportValues

These flags describe what actions will be created by createActions() after passing a combination of these flags to setRichTextSupport().

Enumerator:

  DisableRichText = 0x00 |
  SupportBold = 0x01 |
  SupportItalic = 0x02 |
  SupportUnderline = 0x04 |
  SupportStrikeOut = 0x08 |
  SupportFontFamily = 0x10 |
  SupportFontSize = 0x20 |
  SupportTextForegroundColor = 0x40 |
  SupportTextBackgroundColor = 0x80 |
  FullTextFormattingSupport = 0xff |
  SupportChangeListStyle = 0x100 |
  SupportIndentLists = 0x200 |
  SupportDedentLists = 0x400 |
  FullListSupport = 0xf00 |
  SupportAlignment = 0x100000 |
  SupportRuleLine = 0x400000 |
  SupportHyperlinks = 0x800000 |
  SupportFormatPainting = 0x1000000 |
  SupportToPlainText = 0x2000000 |
  SupportSuperScriptAndSubScript = 0x4000000 |
  FullSupport = 0xffffffff |