KTextWidgets 5.109.0
Public Types | Signals | Public Slots | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
KRichTextEdit

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

#include <KRichTextEdit>

Public Types

enum  Mode { Plain , Rich }
 The mode the edit widget is in. More...
 

Signals

void selectionFinished ()
 Emitted whenever the user has finished making a selection.
 
void textModeChanged (KRichTextEdit::Mode mode)
 Emitted whenever the text mode is changed.
 
- Signals inherited from KTextEdit
void aboutToShowContextMenu (QMenu *menu)
 Emitted before the context menu is displayed.
 
void checkSpellingChanged (bool)
 emit signal when we activate or not autospellchecking
 
void languageChanged (const QString &language)
 Emitted when the user changes the language in the spellcheck dialog shown by checkSpelling() or when calling setSpellCheckingLanguage().
 
void spellCheckerAutoCorrect (const QString &currentWord, const QString &autoCorrectWord)
 
void spellCheckingCanceled ()
 signal spellCheckingCanceled is sent when we cancel spell checking.
 
void spellCheckingFinished ()
 signal spellCheckingFinished is sent when we finish spell check or we click on "Terminate" button in sonnet dialogbox
 
void spellCheckStatus (const QString &)
 Signal sends when spell checking is finished/stopped/completed.
 

Public Slots

void alignCenter ()
 Sets the alignment of the current block to Centered.
 
void alignJustify ()
 Sets the alignment of the current block to Justified.
 
void alignLeft ()
 Sets the alignment of the current block to Left Aligned.
 
void alignRight ()
 Sets the alignment of the current block to Right Aligned.
 
void indentListLess ()
 Decreases the nesting level of the current block or selected blocks.
 
void indentListMore ()
 Increases the nesting level of the current block or selected blocks.
 
void insertHorizontalRule ()
 Inserts a horizontal rule below the current block.
 
void insertPlainTextImplementation ()
 
void makeLeftToRight ()
 Sets the direction of the current block to Left-To-Right.
 
void makeRightToLeft ()
 Sets the direction of the current block to Right-To-Left.
 
void setFont (const QFont &font)
 Sets the current word or selection to the font font.
 
void setFontFamily (const QString &fontFamily)
 Sets the current word or selection to the font family fontFamily.
 
void setFontSize (int size)
 Sets the current word or selection to the font size size.
 
void setHeadingLevel (int level)
 Sets the heading level of a current block or selection.
 
void setListStyle (int _styleIndex)
 Sets the list style of the current list, or creates a new list using the current block.
 
void setTextBackgroundColor (const QColor &color)
 Sets the background color of the current word or selection to color.
 
void setTextBold (bool bold)
 Toggles the bold formatting of the current word or selection at the current cursor position.
 
void setTextForegroundColor (const QColor &color)
 Sets the foreground color of the current word or selection to color.
 
void setTextItalic (bool italic)
 Toggles the italic formatting of the current word or selection at the current cursor position.
 
void setTextStrikeOut (bool strikeOut)
 Toggles the strikeout formatting of the current word or selection at the current cursor position.
 
void setTextSubScript (bool subscript)
 Toggles the subscript formatting of the current word or selection at the current cursor position.
 
void setTextSuperScript (bool superscript)
 Toggles the superscript formatting of the current word or selection at the current cursor position.
 
void setTextUnderline (bool underline)
 Toggles the underline formatting of the current word or selection at the current cursor position.
 
void switchToPlainText ()
 This will switch the editor to plain text mode.
 
QString toCleanHtml () const
 This will clean some of the bad html produced by the underlying QTextEdit It walks over all lines and cleans up a bit.
 
- Public Slots inherited from KTextEdit
void addTextDecorator (Sonnet::SpellCheckDecorator *decorator)
 Add custom spell checker decorator.
 
void checkSpelling ()
 Show a dialog to check the spelling.
 
void clearDecorator ()
 clearDecorator clear the spellcheckerdecorator
 
void replace ()
 Create replace dialogbox.
 
void setSpellCheckingLanguage (const QString &language)
 Set the spell check language which will be used for highlighting spelling mistakes and for the spellcheck dialog.
 
void showSpellConfigDialog (const QString &windowIcon=QString())
 Opens a Sonnet::ConfigDialog for this text edit.
 

Public Member Functions

 KRichTextEdit (const QString &text, QWidget *parent=nullptr)
 Constructs a KRichTextEdit object.
 
 KRichTextEdit (QWidget *parent=nullptr)
 Constructs a KRichTextEdit object.
 
 ~KRichTextEdit () override
 Destructor.
 
bool canDedentList () const
 Returns true if the list item at the current position can be dedented.
 
bool canIndentList () const
 Returns true if the list item at the current position can be indented.
 
QString currentLinkText () const
 Returns the text of the link at the current position or an empty string if the cursor is not on a link.
 
QString currentLinkUrl () const
 Returns the URL target (href) of the link at the current position or an empty string if the cursor is not on a link.
 
void enableRichTextMode ()
 This enables rich text mode.
 
void selectLinkText () const
 Convenience function to select the link text using the active cursor.
 
void selectLinkText (QTextCursor *cursor) const
 If the cursor is on a link, sets the cursor to a selection of the text of the link.
 
void setTextOrHtml (const QString &text)
 Replaces all the content of the text edit with the given string.
 
Mode textMode () const
 
QString textOrHtml () const
 
void updateLink (const QString &linkUrl, const QString &linkText)
 Replaces the current selection with a hyperlink with the link URL linkUrl and the link text linkText.
 
- Public Member Functions inherited from KTextEdit
 KTextEdit (const QString &text, QWidget *parent=nullptr)
 Constructs a KTextEdit object.
 
 KTextEdit (QWidget *parent=nullptr)
 Constructs a KTextEdit object.
 
 ~KTextEdit () override
 Destroys the KTextEdit object.
 
virtual bool checkSpellingEnabled () const
 Returns true if background spell checking is enabled for this text edit.
 
virtual void createHighlighter ()
 Allows to create a specific highlighter if reimplemented.
 
void enableFindReplace (bool enabled)
 Enable find replace action.
 
void forceSpellChecking ()
 
Sonnet::Highlighter * highlighter () const
 Returns the current highlighter, which is 0 if spell checking is disabled.
 
void highlightWord (int length, int pos)
 Selects the characters at the specified position.
 
virtual QMenu * mousePopupMenu ()
 Return standard KTextEdit popupMenu.
 
virtual void setCheckSpellingEnabled (bool check)
 Turns background spell checking for this text edit on or off.
 
void setHighlighter (Sonnet::Highlighter *_highLighter)
 Sets a custom background spell highlighter for this text edit.
 
virtual void setReadOnly (bool readOnly)
 Reimplemented to set a proper "deactivated" background color.
 
virtual bool shouldBlockBeSpellChecked (const QString &block) const
 Returns true if the given paragraph or block should be spellcheck.
 
void showAutoCorrectButton (bool show)
 
void showTabAction (bool show)
 
const QString & spellCheckingLanguage () const
 

Protected Member Functions

 __attribute__ ((visibility("hidden"))) KRichTextEdit(KRichTextEditPrivate &dd
 
 __attribute__ ((visibility("hidden"))) KRichTextEdit(KRichTextEditPrivate &dd
 
void keyPressEvent (QKeyEvent *event) override
 Reimplemented.
 
- Protected Member Functions inherited from KTextEdit
KTEXTWIDGETS_NO_EXPORT KTextEdit (KTextEditPrivate &dd, const QString &text, QWidget *parent)
 
KTEXTWIDGETS_NO_EXPORT KTextEdit (KTextEditPrivate &dd, QWidget *parent)
 
void contextMenuEvent (QContextMenuEvent *) override
 Reimplemented from QTextEdit to add spelling related items when appropriate.
 
virtual void deleteWordBack ()
 Deletes a word backwards from the current cursor position, if available.
 
virtual void deleteWordForward ()
 Deletes a word forwards from the current cursor position, if available.
 
bool event (QEvent *) override
 Reimplemented to catch "delete word" shortcut events.
 
void focusInEvent (QFocusEvent *) override
 Reimplemented to instantiate a KDictSpellingHighlighter, if spellchecking is enabled.
 
void keyPressEvent (QKeyEvent *) override
 Reimplemented for internal reasons.
 

Protected Attributes

const QString QWidget * parent
 
QWidget * parent
 
const QString & text
 

Additional Inherited Members

- Properties inherited from KTextEdit
bool checkSpellingEnabled
 
QString spellCheckingLanguage
 
- Protected Slots inherited from KTextEdit
void slotDoFind ()
 
void slotDoReplace ()
 
void slotFind ()
 
void slotFindNext ()
 
void slotFindPrevious ()
 
void slotReplace ()
 
void slotReplaceNext ()
 
void slotSpeakText ()
 

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:

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

KRichTextEdit Widget
Since
4.1

Member Enumeration Documentation

◆ Mode

The mode the edit widget is in.

Enumerator
Plain 

Plain text mode.

Rich 

Rich text mode.

Constructor & Destructor Documentation

◆ KRichTextEdit() [1/2]

KRichTextEdit::KRichTextEdit ( const QString &  text,
QWidget *  parent = nullptr 
)
explicit

Constructs a KRichTextEdit object.

Parameters
textThe initial text of the text edit, which is interpreted as HTML.
parentThe parent widget

◆ KRichTextEdit() [2/2]

KRichTextEdit::KRichTextEdit ( QWidget *  parent = nullptr)
explicit

Constructs a KRichTextEdit object.

Parameters
parentThe parent widget

◆ ~KRichTextEdit()

KRichTextEdit::~KRichTextEdit ( )
override

Destructor.

Member Function Documentation

◆ alignCenter

void KRichTextEdit::alignCenter ( )
slot

Sets the alignment of the current block to Centered.

◆ alignJustify

void KRichTextEdit::alignJustify ( )
slot

Sets the alignment of the current block to Justified.

◆ alignLeft

void KRichTextEdit::alignLeft ( )
slot

Sets the alignment of the current block to Left Aligned.

◆ alignRight

void KRichTextEdit::alignRight ( )
slot

Sets the alignment of the current block to Right Aligned.

◆ canDedentList()

bool KRichTextEdit::canDedentList ( ) const

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

See also
canIndentList

◆ canIndentList()

bool KRichTextEdit::canIndentList ( ) const

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

See also
canDedentList

◆ currentLinkText()

QString KRichTextEdit::currentLinkText ( ) const

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

QString KRichTextEdit::currentLinkUrl ( ) const

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

void KRichTextEdit::enableRichTextMode ( )

This enables rich text mode.

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

◆ indentListLess

void KRichTextEdit::indentListLess ( )
slot

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

See also
canDedentList

◆ indentListMore

void KRichTextEdit::indentListMore ( )
slot

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

See also
canIndentList

◆ insertHorizontalRule

void KRichTextEdit::insertHorizontalRule ( )
slot

Inserts a horizontal rule below the current block.

◆ insertPlainTextImplementation

void KRichTextEdit::insertPlainTextImplementation ( )
slot
Since
4.10 Because of binary compatibility constraints, insertPlainText is not virtual. Therefore it must dynamically detect and call this slot.

◆ keyPressEvent()

void KRichTextEdit::keyPressEvent ( QKeyEvent *  event)
overrideprotected

Reimplemented.

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

◆ makeLeftToRight

void KRichTextEdit::makeLeftToRight ( )
slot

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

Since
4.6

◆ makeRightToLeft

void KRichTextEdit::makeRightToLeft ( )
slot

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

Since
4.6

◆ selectionFinished

void KRichTextEdit::selectionFinished ( )
signal

Emitted whenever the user has finished making a selection.

(on mouse up)

Deprecated:
Since 4.1, no longer emitted.

◆ selectLinkText() [1/2]

void KRichTextEdit::selectLinkText ( ) const

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

See also
selectLinkText

◆ selectLinkText() [2/2]

void KRichTextEdit::selectLinkText ( QTextCursor *  cursor) const

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.

Parameters
cursorThe cursor to use to select the text.
See also
updateLink

◆ setFont

void KRichTextEdit::setFont ( const QFont &  font)
slot

Sets the current word or selection to the font font.

Parameters
fontthe font of the text will be set to this font

◆ setFontFamily

void KRichTextEdit::setFontFamily ( const QString &  fontFamily)
slot

Sets the current word or selection to the font family fontFamily.

Parameters
fontFamilyThe text's font family will be changed to this one

◆ setFontSize

void KRichTextEdit::setFontSize ( int  size)
slot

Sets the current word or selection to the font size size.

Parameters
sizeThe text's font will get this size

◆ setHeadingLevel

void KRichTextEdit::setHeadingLevel ( int  level)
slot

Sets the heading level of a current block or selection.

Parameters
levelHeading level (value should be between 0 and 6) (0 is "normal text", 1 is the largest heading, 6 is the smallest one)
Since
5.70

◆ setListStyle

void KRichTextEdit::setListStyle ( int  _styleIndex)
slot

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
_styleIndexThe list will get this style

◆ setTextBackgroundColor

void KRichTextEdit::setTextBackgroundColor ( const QColor &  color)
slot

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

Parameters
colorThe text will get this foreground color

◆ setTextBold

void KRichTextEdit::setTextBold ( bool  bold)
slot

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

Parameters
boldIf true, the text will be set to bold

◆ setTextForegroundColor

void KRichTextEdit::setTextForegroundColor ( const QColor &  color)
slot

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

Parameters
colorThe text will get this background color

◆ setTextItalic

void KRichTextEdit::setTextItalic ( bool  italic)
slot

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

Parameters
italicIf true, the text will be set to italic

◆ setTextOrHtml()

void KRichTextEdit::setTextOrHtml ( const 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
textThe text to insert

◆ setTextStrikeOut

void KRichTextEdit::setTextStrikeOut ( bool  strikeOut)
slot

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

Parameters
strikeOutIf true, the text will be struck out

◆ setTextSubScript

void KRichTextEdit::setTextSubScript ( bool  subscript)
slot

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

Parameters
subscriptIf true, the text will be set to subscript

◆ setTextSuperScript

void KRichTextEdit::setTextSuperScript ( bool  superscript)
slot

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

Parameters
superscriptIf true, the text will be set to superscript

◆ setTextUnderline

void KRichTextEdit::setTextUnderline ( bool  underline)
slot

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

Parameters
underlineIf true, the text will be underlined

◆ switchToPlainText

void KRichTextEdit::switchToPlainText ( )
slot

This will switch the editor to plain text mode.

All rich text formatting will be destroyed.

◆ textMode()

Mode KRichTextEdit::textMode ( ) const
Returns
The current text mode

◆ textModeChanged

void KRichTextEdit::textModeChanged ( KRichTextEdit::Mode  mode)
signal

Emitted whenever the text mode is changed.

Parameters
modeThe new text mode

◆ textOrHtml()

QString KRichTextEdit::textOrHtml ( ) const
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

QString KRichTextEdit::toCleanHtml ( ) const
slot

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

void KRichTextEdit::updateLink ( const QString &  linkUrl,
const QString &  linkText 
)

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

See also
selectLinkText
currentLinkUrl
currentLinkText
Parameters
linkUrlThe link will get this URL as href (target)
linkTextThe link will get this alternative text, which is the text displayed in the text edit.