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

📄 qlineedit.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                    actually entered.    \sa setEchoMode() echoMode()*//*!    \property QLineEdit::echoMode    \brief the line edit's echo mode    The initial setting is \l Normal, but QLineEdit also supports \l    NoEcho and \l Password modes.    The widget's display and the ability to copy or drag the text is    affected by this setting.    \sa EchoMode displayText()*/QLineEdit::EchoMode QLineEdit::echoMode() const{    Q_D(const QLineEdit);    return (EchoMode) d->echoMode;}void QLineEdit::setEchoMode(EchoMode mode){    Q_D(QLineEdit);    if(mode == (EchoMode)d->echoMode)        return;    d->echoMode = mode;    d->updateTextLayout();    update();#ifdef Q_WS_MAC    if (hasFocus())        qt_mac_secure_keyboard(d->echoMode == Password || d->echoMode == NoEcho);#endif}#ifndef QT_NO_VALIDATOR/*!    Returns a pointer to the current input validator, or 0 if no    validator has been set.    \sa setValidator()*/const QValidator * QLineEdit::validator() const{    Q_D(const QLineEdit);    return d->validator;}/*!    Sets this line edit to only accept input that the validator, \a v,    will accept. This allows you to place any arbitrary constraints on    the text which may be entered.    If \a v == 0, setValidator() removes the current input validator.    The initial setting is to have no input validator (i.e. any input    is accepted up to maxLength()).    \sa validator() QIntValidator QDoubleValidator QRegExpValidator*/void QLineEdit::setValidator(const QValidator *v){    Q_D(QLineEdit);    d->validator = const_cast<QValidator*>(v);}#endif // QT_NO_VALIDATOR/*!    Returns a recommended size for the widget.    The width returned, in pixels, is usually enough for about 15 to    20 characters.*/QSize QLineEdit::sizeHint() const{    Q_D(const QLineEdit);    ensurePolished();    QFontMetrics fm(font());    int h = qMax(fm.lineSpacing(), 14) + 2*verticalMargin;    int w = fm.width('x') * 17 + 2*horizontalMargin; // "some"    int m = d->frame ? style()->pixelMetric(QStyle::PM_DefaultFrameWidth) : 0;    QStyleOptionFrame opt;    opt.rect = rect();    opt.palette = palette();    opt.state = QStyle::State_None;    return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w + (2 * m), h + (2 * m)).                                      expandedTo(QApplication::globalStrut()), this));}/*!    Returns a minimum size for the line edit.    The width returned is enough for at least one character.*/QSize QLineEdit::minimumSizeHint() const{    Q_D(const QLineEdit);    ensurePolished();    QFontMetrics fm = fontMetrics();    int h = fm.height() + qMax(2*horizontalMargin, fm.leading());    int w = fm.maxWidth();    int m = d->frame ? style()->pixelMetric(QStyle::PM_DefaultFrameWidth) : 0;    return QSize(w + (2 * m), h + (2 * m));}/*!    \property QLineEdit::cursorPosition    \brief the current cursor position for this line edit    Setting the cursor position causes a repaint when appropriate.*/int QLineEdit::cursorPosition() const{    Q_D(const QLineEdit);    return d->cursor;}void QLineEdit::setCursorPosition(int pos){    Q_D(QLineEdit);    if (pos < 0)        pos = 0;    if (pos <= d->text.length())        d->moveCursor(pos);}/*!    Returns the cursor position under the point \a pos.*/// ### What should this do if the point is outside of contentsRect? Currently returns 0.int QLineEdit::cursorPositionAt(const QPoint &pos){    Q_D(QLineEdit);    return d->xToPos(pos.x());}#ifdef QT3_SUPPORT/*! \obsolete    Use setText(), setCursorPosition() and setSelection() instead.*/bool QLineEdit::validateAndSet(const QString &newText, int newPos,                                 int newMarkAnchor, int newMarkDrag){    Q_D(QLineEdit);    int priorState = d->undoState;    d->selstart = 0;    d->selend = d->text.length();    d->removeSelectedText();    d->insert(newText);    d->finishChange(priorState);    if (d->undoState > priorState) {        d->cursor = newPos;        d->selstart = qMin(newMarkAnchor, newMarkDrag);        d->selend = qMax(newMarkAnchor, newMarkDrag);        update();        d->emitCursorPositionChanged();        return true;    }    return false;}#endif //QT3_SUPPORT/*!    \property QLineEdit::alignment    \brief the alignment of the line edit    Only horizontal alignments are allowed in here, Qt::AlignJustify    will map to Qt::AlignLeft.    \sa Qt::Alignment*/Qt::Alignment QLineEdit::alignment() const{    Q_D(const QLineEdit);    return QFlag(d->alignment);}void QLineEdit::setAlignment(Qt::Alignment alignment){    Q_D(QLineEdit);    d->alignment = alignment & Qt::AlignHorizontal_Mask;    update();}/*!    Moves the cursor forward \a steps characters. If \a mark is true    each character moved over is added to the selection; if \a mark is    false the selection is cleared.    \sa cursorBackward()*/void QLineEdit::cursorForward(bool mark, int steps){    Q_D(QLineEdit);    int cursor = d->cursor;    if (steps > 0) {        while(steps--)            cursor = d->textLayout.nextCursorPosition(cursor);    } else if (steps < 0) {        while (steps++)            cursor = d->textLayout.previousCursorPosition(cursor);    }    d->moveCursor(cursor, mark);}/*!    Moves the cursor back \a steps characters. If \a mark is true each    character moved over is added to the selection; if \a mark is    false the selection is cleared.    \sa cursorForward()*/void QLineEdit::cursorBackward(bool mark, int steps){    cursorForward(mark, -steps);}/*!    Moves the cursor one word forward. If \a mark is true, the word is    also selected.    \sa cursorWordBackward()*/void QLineEdit::cursorWordForward(bool mark){    Q_D(QLineEdit);    d->moveCursor(d->textLayout.nextCursorPosition(d->cursor, QTextLayout::SkipWords), mark);}/*!    Moves the cursor one word backward. If \a mark is true, the word    is also selected.    \sa cursorWordForward()*/void QLineEdit::cursorWordBackward(bool mark){    Q_D(QLineEdit);    d->moveCursor(d->textLayout.previousCursorPosition(d->cursor, QTextLayout::SkipWords), mark);}/*!    If no text is selected, deletes the character to the left of the    text cursor and moves the cursor one position to the left. If any    text is selected, the cursor is moved to the beginning of the    selected text and the selected text is deleted.    \sa del()*/void QLineEdit::backspace(){    Q_D(QLineEdit);    int priorState = d->undoState;    if (d->hasSelectedText()) {        d->removeSelectedText();    } else if (d->cursor) {            --d->cursor;            if (d->maskData)                d->cursor = d->prevMaskBlank(d->cursor);            QChar uc = d->text.at(d->cursor);            if (d->cursor > 0 && uc.unicode() >= 0xdc00 && uc.unicode() < 0xe000) {                // second half of a surrogate, check if we have the first half as well,                // if yes delete both at once                uc = d->text.at(d->cursor - 1);                if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00) {                    d->del(true);                    --d->cursor;                }            }            d->del(true);    }    d->finishChange(priorState);}/*!    If no text is selected, deletes the character to the right of the    text cursor. If any text is selected, the cursor is moved to the    beginning of the selected text and the selected text is deleted.    \sa backspace()*/void QLineEdit::del(){    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);

⌨️ 快捷键说明

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