QLineEdit
功能:单行文本编辑框
说明:只能是纯文本,不能是富文本
所属模块:PyQt5.QtWidgets
继承结构:
一. 属性
enum | ActionPosition { LeadingPosition, TrailingPosition } 行为的位置:LeadingPosition前面,TrailingPosition后面 |
enum | EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit } 文本输出模式:Normal=0 正常输出,NoEcho=1 无输出,Password=2 密文,PasswordEchoOnEdit=3 编辑时明文,结束后密文 |
QLineEdit(const QString &contents, QWidget *parent = nullptr) 创建带有初始内容的单行文本编辑框 | |
QLineEdit(QWidget *parent = nullptr) | |
void | addAction(QAction *action, QLineEdit.ActionPosition position) 添加操作行为,常设置明文和密文的切换 |
QAction * | addAction(const QIcon &icon, QLineEdit.ActionPosition position) |
Qt::Alignment | alignment() const 返回当前对齐方式 |
void | backspace() 退格,若有选中的文本则删除,若没有则删除光标左侧一个字符 |
QCompleter * | completer() const 返回完成器 |
QMenu * | createStandardContextMenu() |
void | cursorBackward(bool mark, int steps = 1) 光标向后(向左)移动steps,mask为true表示移动的过程中选中文本,以下的mask同理 |
void | cursorForward(bool mark, int steps = 1) 光标向前(向右)移动steps |
Qt::CursorMoveStyle | cursorMoveStyle() const 返回光标移动的样式 |
int | cursorPosition() const 返回光标的位置 |
int | cursorPositionAt(const QPoint &pos) 返回当前光标的位置,从0开始,传入的是坐标,单位是像素,不常用 |
void | cursorWordBackward(bool mark) 光标向后(向左)移动一个单词 |
void | cursorWordForward(bool mark) 光标向前(向右)移动一个单词 |
void | del() 删除,若有选中的文本则删除,若没有则删除光标右侧一个字符 |
void | clear() 清空文本框所有内容 |
void | deselect() 取消选中已选中的文本 |
QString | displayText() const 返回用户看到的内容,密码格式,获得的是小星星 |
bool | dragEnabled() const 返回选中的文本是否拖拽 |
QLineEdit::EchoMode | echoMode() const 返回当前的输出模式 |
void | end(bool mark) 光标移动到行尾 |
bool | hasAcceptableInput() const |
bool | hasFrame() const |
bool | hasSelectedText() const |
void | home(bool mark) 光标移动到行首 |
QString | inputMask() const |
void | insert(const QString &newText) 在光标处插入文本 |
bool | isClearButtonEnabled() const 返回清空按钮是否使能 |
bool | isModified() const 返回文本内容是否被修改 |
bool | isReadOnly() const 返回该文本框是否是只读的 |
bool | isRedoAvailable() const 返回是否重做 |
bool | isUndoAvailable() const 返回是否撤销 |
int | maxLength() const 返回该文本框允许的最长字符个数 |
QString | placeholderText() const 返回占位文本 |
void | selectAll() 选中所有文本 |
QString | selectedText() const 返回选中的文本 |
int | selectionEnd() const 选中文本的结束位置 |
int | selectionLength() const 选中文本的长度 |
int | selectionStart() const 选中文本的开始位置 |
void | setAlignment(Qt::Alignment flag) 设置文本对齐方式 |
void | setClearButtonEnabled(bool enable) 设置清空按钮![]() |
void | setCompleter(QCompleter *c) 设置完成器,用于自动补全 |
void | setCursorMoveStyle(Qt::CursorMoveStyle style) |
void | setCursorPosition(int) 设置光标的位置,若传入小数,则向下取整,即1.5取为1 |
void | setDragEnabled(bool b) 设置文本选中后是否可以拖拽 |
void | setEchoMode(QLineEdit.EchoMode) 设置输出模式 |
void | setFrame(bool) |
void | setInputMask(const QString &inputMask) 掩码验证 |
void | setMaxLength(int) 对内容限制,限制最大长度 |
void | setModified(bool) 设置文本内容是否被修改过 |
void | setPlaceholderText(const QString &) 设置占位文本,通常用于提示信息 |
void | setReadOnly(bool) 对内容限制,限制只读 |
void | setSelection(int start, int length) 设置文本选中的范围 |
void | setTextMargins(int left, int top, int right, int bottom) 设置文本边距,文本距离边框的距离,单位是像素 |
void | setTextMargins(const QMargins &margins) 设置文本边距 |
void | setValidator(const QValidator *v) 设置验证器,对输入文本进行验证 |
void | setText(QString) 设置文本框的内容 |
QString | text() const 返回文本框的真实文本内容,密码 |
QMargins | textMargins() const 返回文本边距 |
const QValidator * | validator() const |
创建行为对象
QAction(const QIcon &icon, const QString &text, QObject *parent = nullptr)
QAction(const QString &text, QObject *parent = nullptr)
QAction(QObject *parent = nullptr)
创建完成器
QCompleter(const QStringList &list, QObject *parent = nullptr)
QCompleter(QAbstractItemModel *model, QObject *parent = nullptr)
QCompleter(QObject *parent = nullptr)
水平对齐
Qt::AlignLeft | 0x0001 | 与左边缘对齐。 |
Qt::AlignRight | 0x0002 | 与右边缘对齐。 |
Qt::AlignHCenter | 0x0004 | 在可用空间中水平居中。 |
Qt::AlignJustify | 0x0008 | 对齐可用空间中的文本。同左对齐 |
垂直对齐
Qt::AlignTop | 0x0020 | 与顶部对齐。 |
Qt::AlignBottom | 0x0040 | 与底部对齐。 |
Qt::AlignVCenter | 0x0080 | 在可用空间中垂直居中。 |
Qt::AlignBaseline | 0x0100 | 与基线对齐。 |
Qt::AlignCenter | AlignVCenter | AlignHCenter | 垂直和水平居中 |
二. 信号
void | cursorPositionChanged(int oldPos, int newPos) 光标位置改变时触发 |
void | editingFinished() 编辑完成时触发 |
void | inputRejected() |
void | returnPressed() 按下enter时触发 |
void | selectionChanged() 选中的文本改变时触发 |
void | textChanged(const QString &text) 文本内容改变时触发 |
void | textEdited(const QString &text) 文本编辑时触发 |
三. 槽
void | clear() 清空文本框 |
void | copy() const 复制选中的文本 |
void | cut() 剪切选中的文本 |
void | paste() 粘贴 |
void | redo() 重做 |
void | selectAll() 选中所有的文本 |
void | setText(const QString &) 设置文本框内容 |
void | undo() 撤销 |