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

📄 qlineedit.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    Q_D(QLineEdit);    int priorState = d->undoState;    if (d->hasSelectedText()) {        d->removeSelectedText();    } else {        int n = d->textLayout.nextCursorPosition(d->cursor) - d->cursor;        while (n--)            d->del();    }    d->finishChange(priorState);}/*!    Moves the text cursor to the beginning of the line unless it is    already there. If \a mark is true, text is selected towards the    first position; otherwise, any selected text is unselected if the    cursor is moved.    \sa end()*/void QLineEdit::home(bool mark){    Q_D(QLineEdit);    d->moveCursor(0, mark);}/*!    Moves the text cursor to the end of the line unless it is already    there. If \a mark is true, text is selected towards the last    position; otherwise, any selected text is unselected if the cursor    is moved.    \sa home()*/void QLineEdit::end(bool mark){    Q_D(QLineEdit);    d->moveCursor(d->text.length(), mark);}/*!    \property QLineEdit::modified    \brief whether the line edit's contents has been modified by the user    The modified flag is never read by QLineEdit; it has a default value    of false and is changed to true whenever the user changes the line    edit's contents.    This is useful for things that need to provide a default value but    do not start out knowing what the default should be (perhaps it    depends on other fields on the form). Start the line edit without    the best default, and when the default is known, if modified()    returns false (the user hasn't entered any text), insert the    default value.    Calling setText() resets the modified flag to false.*/bool QLineEdit::isModified() const{    Q_D(const QLineEdit);    return d->modifiedState != d->undoState;}void QLineEdit::setModified(bool modified){    Q_D(QLineEdit);    if (modified)        d->modifiedState = -1;    else        d->modifiedState = d->undoState;}/*!\fn QLineEdit::clearModified()Use setModified(false) instead.    \sa isModified()*//*!    \property QLineEdit::hasSelectedText    \brief whether there is any text selected    hasSelectedText() returns true if some or all of the text has been    selected by the user; otherwise returns false.    \sa selectedText()*/bool QLineEdit::hasSelectedText() const{    Q_D(const QLineEdit);    return d->hasSelectedText();}/*!    \property QLineEdit::selectedText    \brief the selected text    If there is no selected text this property's value is    an empty string.    \sa hasSelectedText()*/QString QLineEdit::selectedText() const{    Q_D(const QLineEdit);    if (d->hasSelectedText())        return d->text.mid(d->selstart, d->selend - d->selstart);    return QString();}/*!    selectionStart() returns the index of the first selected character in the    line edit or -1 if no text is selected.    \sa selectedText()*/int QLineEdit::selectionStart() const{    Q_D(const QLineEdit);    return d->hasSelectedText() ? d->selstart : -1;}#ifdef QT3_SUPPORT/*!    \fn void QLineEdit::lostFocus()    This signal is emitted when the line edit has lost focus.    Use editingFinished() instead    \sa editingFinished(), returnPressed()*//*!    Use isModified() instead.*/bool QLineEdit::edited() const { return isModified(); }/*!    Use setModified()  or setText().*/void QLineEdit::setEdited(bool on) { setModified(on); }/*!    There exists no equivalent functionality in Qt 4.*/int QLineEdit::characterAt(int xpos, QChar *chr) const{    Q_D(const QLineEdit);    int pos = d->xToPos(xpos + contentsRect().x() - d->hscroll + horizontalMargin);    if (chr && pos < (int) d->text.length())        *chr = d->text.at(pos);    return pos;}/*!    Use selectedText() and selectionStart() instead.*/bool QLineEdit::getSelection(int *start, int *end){    Q_D(QLineEdit);    if (d->hasSelectedText() && start && end) {        *start = d->selstart;        *end = d->selend;        return true;    }    return false;}#endif/*!    Selects text from position \a start and for \a length characters.    Negative lengths are allowed.    \sa deselect() selectAll() selectedText()*/void QLineEdit::setSelection(int start, int length){    Q_D(QLineEdit);    if (start < 0 || start > (int)d->text.length()) {        qWarning("QLineEdit::setSelection: Invalid start position (%d)", start);        return;    } else {        if (length > 0) {            d->selstart = start;            d->selend = qMin(start + length, (int)d->text.length());            d->cursor = d->selend;        } else {            d->selstart = qMax(start + length, 0);            d->selend = start;            d->cursor = d->selstart;        }    }    if (d->hasSelectedText()){        QStyleOptionFrameV2 opt;        initStyleOption(&opt);        if (!style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))            d->setCursorVisible(false);    }    update();    d->emitCursorPositionChanged();}/*!    \property QLineEdit::undoAvailable    \brief whether undo is available*/bool QLineEdit::isUndoAvailable() const{    Q_D(const QLineEdit);    return d->isUndoAvailable();}/*!    \property QLineEdit::redoAvailable    \brief whether redo is available*/bool QLineEdit::isRedoAvailable() const{    Q_D(const QLineEdit);    return d->isRedoAvailable();}/*!    \property QLineEdit::dragEnabled    \brief whether the lineedit starts a drag if the user presses and    moves the mouse on some selected text    Dragging is disabled by default.*/bool QLineEdit::dragEnabled() const{    Q_D(const QLineEdit);    return d->dragEnabled;}void QLineEdit::setDragEnabled(bool b){    Q_D(QLineEdit);    d->dragEnabled = b;}/*!    \property QLineEdit::acceptableInput    \brief whether the input satisfies the inputMask and the    validator.    \sa setInputMask(), setValidator()*/bool QLineEdit::hasAcceptableInput() const{    Q_D(const QLineEdit);    return d->hasAcceptableInput(d->text);}/*!    \property QLineEdit::inputMask    \brief The validation input mask    If no mask is set, inputMask() returns an empty string.    Sets the QLineEdit's validation mask. Validators can be used    instead of, or in conjunction with masks; see setValidator().    Unset the mask and return to normal QLineEdit operation by passing    an empty string ("") or just calling setInputMask() with no    arguments.    The table below shows the characters that can be used in an input mask.    A space character, the default character for a blank, is needed for cases    where a character is \e{permitted but not required}.    \table    \header \i Character \i Meaning    \row \i \c A \i ASCII alphabetic character required. A-Z, a-z.    \row \i \c a \i ASCII alphabetic character permitted but not required.    \row \i \c N \i ASCII alphanumeric character required. A-Z, a-z, 0-9.    \row \i \c n \i ASCII alphanumeric character permitted but not required.    \row \i \c X \i Any character required.    \row \i \c x \i Any character permitted but not required.    \row \i \c 9 \i ASCII digit required. 0-9.    \row \i \c 0 \i ASCII digit permitted but not required.    \row \i \c D \i ASCII digit required. 1-9.    \row \i \c d \i ASCII digit permitted but not required (1-9).    \row \i \c # \i ASCII digit or plus/minus sign permitted but not required.    \row \i \c H \i Hexadecimal character required. A-F, a-f, 0-9.    \row \i \c h \i Hexadecimal character permitted but not required.    \row \i \c B \i Binary character required. 0-1.    \row \i \c b \i Binary character permitted but not required.    \row \i \c > \i All following alphabetic characters are uppercased.    \row \i \c < \i All following alphabetic characters are lowercased.    \row \i \c ! \i Switch off case conversion.    \row \i \tt{\\} \i Use \tt{\\} to escape the special                           characters listed above to use them as                           separators.    \endtable    The mask consists of a string of mask characters and separators,    optionally followed by a semicolon and the character used for    blanks. The blank characters are always removed from the text    after editing.    Examples:    \table    \header \i Mask \i Notes    \row \i \c 000.000.000.000;_ \i IP address; blanks are \c{_}.    \row \i \c HH:HH:HH:HH:HH:HH;_ \i MAC address    \row \i \c 0000-00-00 \i ISO Date; blanks are \c space    \row \i \c >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# \i License number;    blanks are \c - and all (alphabetic) characters are converted to    uppercase.    \endtable    To get range control (e.g. for an IP address) use masks together    with \link setValidator() validators\endlink.    \sa maxLength*/QString QLineEdit::inputMask() const{    Q_D(const QLineEdit);    return (d->maskData ? d->inputMask + QLatin1Char(';') + d->blank : QString());}void QLineEdit::setInputMask(const QString &inputMask){    Q_D(QLineEdit);    d->parseInputMask(inputMask);    if (d->maskData)        d->moveCursor(d->nextMaskBlank(0));}/*!    Selects all the text (i.e. highlights it) and moves the cursor to    the end. This is useful when a default value has been inserted    because if the user types before clicking on the widget, the    selected text will be deleted.    \sa setSelection() deselect()*/void QLineEdit::selectAll(){    Q_D(QLineEdit);    d->selstart = d->selend = d->cursor = 0;    d->moveCursor(d->text.length(), true);}/*!    Deselects any selected text.    \sa setSelection() selectAll()*/void QLineEdit::deselect(){    Q_D(QLineEdit);    d->deselect();    d->finishChange();}/*!    Deletes any selected text, inserts \a newText, and validates the    result. If it is valid, it sets it as the new contents of the line    edit.    \sa setText(), clear()*/void QLineEdit::insert(const QString &newText){//     q->resetInputContext(); //#### FIX ME IN QT    Q_D(QLineEdit);    int priorState = d->undoState;    d->removeSelectedText();    d->insert(newText);    d->finishChange(priorState);}/*!    Clears the contents of the line edit.    \sa setText(), insert()*/void QLineEdit::clear(){    Q_D(QLineEdit);    int priorState = d->undoState;    resetInputContext();    d->selstart = 0;    d->selend = d->text.length();    d->removeSelectedText();    d->separate();    d->finishChange(priorState);}/*!    Undoes the last operation if undo is \link    QLineEdit::undoAvailable available\endlink. Deselects any current    selection, and updates the selection start to the current cursor    position.*/void QLineEdit::undo(){    Q_D(QLineEdit);    resetInputContext();    d->undo();    d->finishChange(-1, true);}/*!    Redoes the last operation if redo is \link    QLineEdit::redoAvailable available\endlink.*/void QLineEdit::redo(){    Q_D(QLineEdit);    resetInputContext();    d->redo();    d->finishChange();}/*!    \property QLineEdit::readOnly    \brief whether the line edit is read only.    In read-only mode, the user can still copy the text to the    clipboard, or drag and drop the text (if echoMode() is \l Normal),    but cannot edit it.    QLineEdit does not show a cursor in read-only mode.    \sa setEnabled()*/bool QLineEdit::isReadOnly() const{    Q_D(const QLineEdit);    return d->readOnly;

⌨️ 快捷键说明

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