⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtextedit.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{    if (cursor.isNull())        return;    cursor.setPosition(undoPosition + charsAdded);    // don't call ensureCursorVisible here but wait until the text is layouted, which will    // be the case in QTextEdit::undo() after calling undo() on the document.}/*!    \class QTextEdit    \brief The QTextEdit class provides a widget that is used to edit and display    both plain and rich text.    \ingroup text    \mainclass    \tableofcontents    \section1 Introduction and Concepts    QTextEdit is an advanced WYSIWYG viewer/editor supporting rich    text formatting using HTML-style tags. It is optimized to handle    large documents and to respond quickly to user input.    QTextEdit works on paragraphs and characters. A paragraph is a    formatted string which is word-wrapped to fit into the width of    the widget. By default when reading plain text, one newline    signifies a paragraph. A document consists of zero or more    paragraphs. The words in the paragraph are aligned in accordance    with the paragraph's alignment. Paragraphs are separated by hard    line breaks. Each character within a paragraph has its own    attributes, for example, font and color.    QTextEdit can display images, lists and tables. If the text is    too large to view within the text edit's viewport, scrollbars will    appear. The text edit can load both plain text and HTML files (a    subset of HTML 3.2 and 4).    If you just need to display a small piece of rich text use QLabel.    Note that we do not intend to add a full-featured web browser    widget to Qt (because that would easily double Qt's size and only    a few applications would benefit from it). The rich    text support in Qt is designed to provide a fast, portable and    efficient way to add reasonable online help facilities to    applications, and to provide a basis for rich text editors.    \section1 Using QTextEdit as a Display Widget    QTextEdit can display a large HTML subset, including tables and    images.    The text is set or replaced using setHtml() which deletes any    existing text and replaces it with the text passed in the    setHtml() call. If you call setHtml() with legacy HTML, and then    call text(), the text that is returned may have different markup,    but will render the same. The entire text can be deleted with clear().    Text itself can be inserted using the QTextCursor class or using the    convenience functions insertHtml(), insertPlainText(), append() or    paste(). QTextCursor is also able to insert complex objects like tables    or lists into the document, and it deals with creating selections    and applying changes to selected text.    By default the text edit wraps words at whitespace to fit within    the text edit widget. The setLineWrapMode() function is used to    specify the kind of line wrap you want, or \l NoWrap if you don't    want any wrapping. Call setLineWrapMode() to set a fixed pixel width    \l FixedPixelWidth, or character column (e.g. 80 column) \l    FixedColumnWidth with the pixels or columns specified with    setLineWrapColumnOrWidth(). If you use word wrap to the widget's width    \l WidgetWidth, you can specify whether to break on whitespace or    anywhere with setWordWrapMode().    The find() function can be used to find and select a given string    within the text.    \section2 Read-only Key Bindings    When QTextEdit is used read-only the key bindings are limited to    navigation, and text may only be selected with the mouse:    \table    \header \i Keypresses \i Action    \row \i Qt::UpArrow        \i Moves one line up.    \row \i Qt::DownArrow        \i Moves one line down.    \row \i Qt::LeftArrow        \i Moves one character to the left.    \row \i Qt::RightArrow        \i Moves one character to the right.    \row \i PageUp        \i Moves one (viewport) page up.    \row \i PageDown        \i Moves one (viewport) page down.    \row \i Home        \i Moves to the beginning of the text.    \row \i End                \i Moves to the end of the text.    \row \i Alt+Wheel         \i Scrolls the page horizontally (the Wheel is the mouse wheel).    \row \i Ctrl+Wheel        \i Zooms the text.    \row \i Ctrl+A            \i Selects all text.    \endtable    The text edit may be able to provide some meta-information. For    example, the documentTitle() function will return the text from    within HTML \c{<title>} tags.    \section1 Using QTextEdit as an Editor    All the information about using QTextEdit as a display widget also    applies here.    The current char format's attributes are set with setFontItalic(),    setFontWeight(), setFontUnderline(), setFontFamily(),    setFontPointSize(), setTextColor() and setCurrentFont(). The current    paragraph's alignment is set with setAlignment().    Selection of text is handled by the QTextCursor class, which provides    functionality for creating selections, retrieving the text contents or    deleting selections. You can retrieve the object that corresponds with    the user-visible cursor using the textCursor() method. If you want to set    a selection in QTextEdit just create one on a QTextCursor object and    then make that cursor the visible cursor using setCursor(). The selection    can be copied to the clipboard with copy(), or cut to the clipboard with    cut(). The entire text can be selected using selectAll().    When the cursor is moved and the underlying formatting attributes change,    the currentCharFormatChanged() signal is emitted to reflect the new attributes    at the new cursor position.    QTextEdit holds a QTextDocument object which can be retrieved using the    document() method. You can also set your own document object using setDocument().    QTextDocument emits a textChanged() signal if the text changes and it also    provides a isModified() function which will return true if the text has been    modified since it was either loaded or since the last call to setModified    with false as argument. In addition it provides methods for undo and redo.    \section2 Editing Key Bindings    The list of key bindings which are implemented for editing:    \table    \header \i Keypresses \i Action    \row \i Backspace \i Deletes the character to the left of the cursor.    \row \i Delete \i Deletes the character to the right of the cursor.    \row \i Ctrl+C \i Copy the selected text to the clipboard.    \row \i Ctrl+Insert \i Copy the selected text to the clipboard.    \row \i Ctrl+K \i Deletes to the end of the line.    \row \i Ctrl+V \i Pastes the clipboard text into text edit.    \row \i Shift+Insert \i Pastes the clipboard text into text edit.    \row \i Ctrl+X \i Deletes the selected text and copies it to the clipboard.    \row \i Shift+Delete \i Deletes the selected text and copies it to the clipboard.    \row \i Ctrl+Z \i Undoes the last operation.    \row \i Ctrl+Y \i Redoes the last operation.    \row \i LeftArrow \i Moves the cursor one character to the left.    \row \i Ctrl+LeftArrow \i Moves the cursor one word to the left.    \row \i RightArrow \i Moves the cursor one character to the right.    \row \i Ctrl+RightArrow \i Moves the cursor one word to the right.    \row \i UpArrow \i Moves the cursor one line up.    \row \i Ctrl+UpArrow \i Moves the cursor one word up.    \row \i DownArrow \i Moves the cursor one line down.    \row \i Ctrl+Down Arrow \i Moves the cursor one word down.    \row \i PageUp \i Moves the cursor one page up.    \row \i PageDown \i Moves the cursor one page down.    \row \i Home \i Moves the cursor to the beginning of the line.    \row \i Ctrl+Home \i Moves the cursor to the beginning of the text.    \row \i End \i Moves the cursor to the end of the line.    \row \i Ctrl+End \i Moves the cursor to the end of the text.    \row \i Alt+Wheel \i Scrolls the page horizontally (the Wheel is the mouse wheel).    \row \i Ctrl+Wheel \i Zooms the text.    \endtable    To select (mark) text hold down the Shift key whilst pressing one    of the movement keystrokes, for example, \e{Shift+Right Arrow}    will select the character to the right, and \e{Shift+Ctrl+Right    Arrow} will select the word to the right, etc.    \sa QTextDocument QTextCursor document() textCursor() setDocument() setTextCursor()*//*!    \property QTextEdit::undoRedoEnabled    \brief whether undo and redo are enabled    Users are only able to undo or redo actions if this property is    true, and if there is an action that can be undone (or redone).*//*!    \enum QTextEdit::LineWrapMode    \value NoWrap    \value WidgetWidth    \value FixedPixelWidth    \value FixedColumnWidth*//*!    \enum QTextEdit::AutoFormattingFlag    \value AutoNone Don't do any automatic formatting.    \value AutoBulletList Automatically create bullet lists (e.g. when    the user enters an asterisk ('*') in the left most column, or    presses Enter in an existing list item.    \value AutoAll Apply all automatic formatting. Currently only    automatic bullet lists are supported.*//*!    \enum QTextEdit::CursorAction    \value MoveBackward    \value MoveForward    \value MoveWordBackward    \value MoveWordForward    \value MoveUp    \value MoveDown    \value MoveLineStart    \value MoveLineEnd    \value MoveHome    \value MoveEnd    \value MovePageUp    \value MovePageDown    \omitvalue MovePgUp    \omitvalue MovePgDown*//*!    Constructs an empty QTextEdit with parent \a    parent.*/QTextEdit::QTextEdit(QWidget *parent)    : QAbstractScrollArea(*new QTextEditPrivate, parent){    Q_D(QTextEdit);    d->init();}/*!    \internal*/QTextEdit::QTextEdit(QTextEditPrivate &dd, QWidget *parent)    : QAbstractScrollArea(dd, parent){    Q_D(QTextEdit);    d->init();}/*!    Constructs a QTextEdit with parent \a parent. The text edit will display    the text \a text. The text is interpreted as html.*/QTextEdit::QTextEdit(const QString &text, QWidget *parent)    : QAbstractScrollArea(*new QTextEditPrivate, parent){    Q_D(QTextEdit);    d->init(text);}#ifdef QT3_SUPPORT/*!    Use one of the constructors that doesn't take the \a name    argument and then use setObjectName() instead.*/QTextEdit::QTextEdit(QWidget *parent, const char *name)    : QAbstractScrollArea(*new QTextEditPrivate, parent){    Q_D(QTextEdit);    d->init();    setObjectName(QString::fromAscii(name));}#endif/*!    Destructor.*/QTextEdit::~QTextEdit(){}/*!    Returns the point size of the font of the current format.    \sa setFontFamily() setCurrentFont() setFontPointSize()*/qreal QTextEdit::fontPointSize() const{    Q_D(const QTextEdit);    return d->cursor.charFormat().fontPointSize();}/*!    Returns the font family of the current format.    \sa setFontFamily() setCurrentFont() setFontPointSize()*/QString QTextEdit::fontFamily() const{    Q_D(const QTextEdit);    return d->cursor.charFormat().fontFamily();}/*!    Returns the font weight of the current format.    \sa setFontWeight() setCurrentFont() setFontPointSize() QFont::Weight*/int QTextEdit::fontWeight() const{    Q_D(const QTextEdit);    return d->cursor.charFormat().fontWeight();}/*!    Returns true if the font of the current format is underlined; otherwise returns    false.    \sa setFontUnderline()*/bool QTextEdit::fontUnderline() const{    Q_D(const QTextEdit);    return d->cursor.charFormat().fontUnderline();}/*!    Returns true if the font of the current format is italic; otherwise returns    false.    \sa setFontItalic()*/bool QTextEdit::fontItalic() const{    Q_D(const QTextEdit);    return d->cursor.charFormat().fontItalic();}/*!    Returns the text color of the current format.    \sa setTextColor()*/QColor QTextEdit::textColor() const{    Q_D(const QTextEdit);    return d->cursor.charFormat().foreground().color();}/*!    Returns the font of the current format.    \sa setCurrentFont() setFontFamily() setFontPointSize()*/QFont QTextEdit::currentFont() const{    Q_D(const QTextEdit);    return d->cursor.charFormat().font();}/*!    Sets the alignment of the current paragraph to \a a. Valid    alignments are Qt::AlignLeft, Qt::AlignRight,    Qt::AlignJustify and Qt::AlignCenter (which centers    horizontally).*/void QTextEdit::setAlignment(Qt::Alignment a){    Q_D(QTextEdit);    QTextBlockFormat fmt;    fmt.setAlignment(a);    d->cursor.mergeBlockFormat(fmt);    updateMicroFocus();}/*!    Returns the alignment of the current paragraph.    \sa setAlignment()*/Qt::Alignment QTextEdit::alignment() const{    Q_D(const QTextEdit);    return d->cursor.blockFormat().alignment();}/*!    Makes \a document the new document of the text editor.    The parent QObject of the provided document remains the owner    of the object. If the current document is a child of the text    editor, then it is deleted.    \sa document()*/void QTextEdit::setDocument(QTextDocument *document){    Q_D(QTextEdit);    if (d->doc == document)        return;    d->doc->disconnect(this);    d->doc->documentLayout()->disconnect(this);    d->doc->documentLayout()->setPaintDevice(0);    if (d->doc->parent() == this)        delete d->doc;    d->doc = 0;    d->setContent(Qt::RichText, QString(), document);    d->relayoutDocument();}/*!    Returns a pointer to the underlying document.    \sa setDocument()*/QTextDocument *QTextEdit::document() const{    Q_D(const QTextEdit);    return d->doc;}/*!    Sets the visible \a cursor.*/void QTextEdit::setTextCursor(const QTextCursor &cursor)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -