CopperSpice API  1.9.2
QLineEdit Class Reference

Single line text edit widget. More...

Inheritance diagram for QLineEdit:
QWidget QObject QPaintDevice

Public Types

enum  ActionPosition
 
enum  EchoMode
 
- Public Types inherited from QWidget
enum  RenderFlag
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 

Public Signals

void cursorPositionChanged (int oldValue, int newValue)
 
void editingFinished ()
 
void returnPressed ()
 
void selectionChanged ()
 
void textChanged (const QString &newText)
 
void textEdited (const QString &newText)
 
- Public Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 
void windowIconChanged (const QIcon &icon)
 
void windowIconTextChanged (const QString &iconText)
 
void windowTitleChanged (const QString &title)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void clear ()
 
void copy ()
 
void cut ()
 
void paste ()
 
void redo ()
 
void selectAll ()
 
void setText (const QString &str)
 
void undo ()
 
- Public Slots inherited from QWidget
bool close ()
 
void hide ()
 
void lower ()
 
void raise ()
 
void repaint ()
 
void setDisabled (bool disable)
 
void setEnabled (bool enable)
 
void setFocus ()
 
void setHidden (bool hidden)
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool modified)
 
void setWindowTitle (const QString &title)
 
void show ()
 
void showFullScreen ()
 
void showMaximized ()
 
void showMinimized ()
 
void showNormal ()
 
void update ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QLineEdit (const QString &contents, QWidget *parent=nullptr)
 
 QLineEdit (QWidget *parent=nullptr)
 
 ~QLineEdit ()
 
QActionaddAction (const QIcon &icon, ActionPosition position)
 
void addAction (QAction *action)
 
void addAction (QAction *action, ActionPosition position)
 
Qt::Alignment alignment () const
 
void backspace ()
 
QCompletercompleter () const
 
QMenucreateStandardContextMenu ()
 
void cursorBackward (bool mark, int steps=1)
 
void cursorForward (bool mark, int steps=1)
 
Qt::CursorMoveStyle cursorMoveStyle () const
 
int cursorPosition () const
 
int cursorPositionAt (const QPoint &pos)
 
void cursorWordBackward (bool mark)
 
void cursorWordForward (bool mark)
 
void del ()
 
void deselect ()
 
QString displayText () const
 
bool dragEnabled () const
 
EchoMode echoMode () const
 
void end (bool mark)
 
bool event (QEvent *event) override
 
void getTextMargins (int *left, int *top, int *right, int *bottom) const
 
bool hasAcceptableInput () const
 
bool hasFrame () const
 
bool hasSelectedText () const
 
void home (bool mark)
 
QString inputMask () const
 
QVariant inputMethodQuery (Qt::InputMethodQuery query) const override
 
void insert (const QString &newText)
 
bool isClearButtonEnabled () const
 
bool isModified () const
 
bool isReadOnly () const
 
bool isRedoAvailable () const
 
bool isUndoAvailable () const
 
int maxLength () const
 
QSize minimumSizeHint () const override
 
QString placeholderText () const
 
QString selectedText () const
 
int selectionStart () const
 
void setAlignment (Qt::Alignment flag)
 
void setClearButtonEnabled (bool enable)
 
void setCompleter (QCompleter *completer)
 
void setCursorMoveStyle (Qt::CursorMoveStyle style)
 
void setCursorPosition (int)
 
void setDragEnabled (bool enable)
 
void setEchoMode (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 (const QMargins &margins)
 
void setTextMargins (int left, int top, int right, int bottom)
 
void setValidator (const QValidator *validator)
 
QSize sizeHint () const override
 
QString text () const
 
QMargins textMargins () const
 
const QValidatorvalidator () const
 
- Public Methods inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QWidget ()
 
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 
void activateWindow ()
 
void addAction (QAction *action)
 
void addActions (const QList< QAction * > &actions)
 
void adjustSize ()
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 
QBackingStorebackingStore () const
 
QSize baseSize () const
 
QWidget * childAt (const QPoint &position) const
 
QWidget * childAt (int x, int y) const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 
void clearMask ()
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
QCursor cursor () const
 
WId effectiveWinId () const
 
void ensurePolished () const
 
Qt::FocusPolicy focusPolicy () const
 
QWidget * focusProxy () const
 
QWidget * focusWidget () const
 
const QFontfont () const
 
QFontInfo fontInfo () const
 
QFontMetrics fontMetrics () const
 
QPalette::ColorRole foregroundRole () const
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QPixmap grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1)))
 
void grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ())
 
void grabKeyboard ()
 
void grabMouse ()
 
void grabMouse (const QCursor &cursor)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 
QGraphicsEffectgraphicsEffect () const
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 
bool hasEditFocus () const
 
bool hasFocus () const
 
virtual bool hasHeightForWidth () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int width) const
 
Qt::InputMethodHints inputMethodHints () const
 
void insertAction (QAction *before, QAction *action)
 
void insertActions (QAction *before, QList< QAction * > actions)
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *parent) const
 
bool isEnabledToTLW () const
 
bool isFullScreen () const
 
bool isHidden () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isTopLevel () const
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *parent) const
 
bool isWindow () const
 
bool isWindowModified () const
 
QLayoutlayout () const
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
QPoint mapFrom (const QWidget *parent, const QPoint &pos) const
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapFromParent (const QPoint &pos) const
 
QPoint mapTo (const QWidget *parent, const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QPoint mapToParent (const QPoint &pos) const
 
QRegion mask () const
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (const QPoint &point)
 
void move (int x, int y)
 
QWidget * nativeParentWidget () const
 
QWidget * nextInFocusChain () const
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags flags)
 
QPaintEnginepaintEngine () const override
 
const QPalettepalette () const
 
QWidget * parentWidget () const
 
QPoint pos () const
 
QWidget * previousInFocusChain () const
 
QRect rect () const
 
void releaseKeyboard ()
 
void releaseMouse ()
 
void releaseShortcut (int id)
 
void removeAction (QAction *action)
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void repaint (const QRect &rect)
 
void repaint (const QRegion &region)
 
void repaint (int x, int y, int w, int h)
 
void resize (const QSize &size)
 
void resize (int w, int h)
 
bool restoreGeometry (const QByteArray &geometry)
 
QByteArray saveGeometry () const
 
void scroll (int dx, int dy)
 
void scroll (int dx, int dy, const QRect &rect)
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute attribute, bool enable=true)
 
void setAutoFillBackground (bool enable)
 
void setBackgroundRole (QPalette::ColorRole role)
 
void setBaseSize (const QSize &size)
 
void setBaseSize (int basew, int baseh)
 
void setContentsMargins (const QMargins &margins)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &cursor)
 
void setEditFocus (bool enable)
 
void setFixedHeight (int h)
 
void setFixedSize (const QSize &size)
 
void setFixedSize (int w, int h)
 
void setFixedWidth (int w)
 
void setFocus (Qt::FocusReason reason)
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *widget)
 
void setFont (const QFont &font)
 
void setForegroundRole (QPalette::ColorRole role)
 
void setGeometry (const QRect &rect)
 
void setGeometry (int x, int y, int w, int h)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *layout)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &bitmap)
 
void setMask (const QRegion &region)
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &size)
 
void setMaximumSize (int maxw, int maxh)
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &size)
 
void setMinimumSize (int minw, int minh)
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &palette)
 
void setParent (QWidget *parent)
 
void setParent (QWidget *parent, Qt::WindowFlags flags)
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
void setShortcutEnabled (int id, bool enable=true)
 
void setSizeIncrement (const QSize &size)
 
void setSizeIncrement (int w, int h)
 
void setSizePolicy (QSizePolicy policy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
void setStatusTip (const QString &data)
 
void setStyle (QStyle *style)
 
void setToolTip (const QString &data)
 
void setToolTipDuration (int msec)
 
void setUpdatesEnabled (bool enable)
 
void setWhatsThis (const QString &str)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags flags)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &role)
 
void setWindowState (Qt::WindowStates windowState)
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *widget)
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute attribute) const
 
QString toolTip () const
 
int toolTipDuration () const
 
QWidget * topLevelWidget () const
 
bool underMouse () const
 
void ungrabGesture (Qt::GestureType gestureType)
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (const QRect &rect)
 
void update (const QRegion &region)
 
void update (int x, int y, int w, int h)
 
void updateGeometry ()
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 
QString whatsThis () const
 
int width () const
 
QWidget * window () const
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 
QWindowwindowHandle () const
 
QIcon windowIcon () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 
Qt::WindowStates windowState () const
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 
WId winId () const
 
int x () const
 
int y () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Protected Methods

void changeEvent (QEvent *event) override
 
void contextMenuEvent (QContextMenuEvent *event) override
 
QRect cursorRect () const
 
void dragEnterEvent (QDragEnterEvent *event) override
 
void dragLeaveEvent (QDragLeaveEvent *event) override
 
void dragMoveEvent (QDragMoveEvent *event) override
 
void dropEvent (QDropEvent *event) override
 
void focusInEvent (QFocusEvent *event) override
 
void focusOutEvent (QFocusEvent *event) override
 
void initStyleOption (QStyleOptionFrame *option) const
 
void inputMethodEvent (QInputMethodEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
- Protected Methods inherited from QWidget
virtual void actionEvent (QActionEvent *event)
 
virtual void closeEvent (QCloseEvent *event)
 
void create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true)
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 
virtual void enterEvent (QEvent *event)
 
bool event (QEvent *event) override
 
bool focusNextChild ()
 
virtual bool focusNextPrevChild (bool next)
 
bool focusPreviousChild ()
 
virtual void hideEvent (QHideEvent *event)
 
void initPainter (QPainter *painter) const override
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
virtual void leaveEvent (QEvent *event)
 
int metric (PaintDeviceMetric metric) const override
 
virtual void moveEvent (QMoveEvent *event)
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, long *result)
 
virtual void resizeEvent (QResizeEvent *event)
 
virtual void showEvent (QShowEvent *event)
 
virtual void tabletEvent (QTabletEvent *event)
 
virtual void wheelEvent (QWheelEvent *event)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Properties

 acceptableInput
 
 alignment
 
 clearButtonEnabled
 
 cursorMoveStyle
 
 cursorPosition
 
 displayText
 
 dragEnabled
 
 echoMode
 
 frame
 
 hasSelectedText
 
 inputMask
 
 maxLength
 
 modified
 
 placeholderText
 
 readOnly
 
 redoAvailable
 
 selectedText
 
 text
 
 undoAvailable
 
- Properties inherited from QWidget
 acceptDrops
 
 accessibleDescription
 
 accessibleName
 
 autoFillBackground
 
 baseSize
 
 childrenRect
 
 childrenRegion
 
 contextMenuPolicy
 
 cursor
 
 enabled
 
 focus
 
 focusPolicy
 
 font
 
 frameGeometry
 
 frameSize
 
 fullScreen
 
 geometry
 
 height
 
 inputMethodHints
 
 isActiveWindow
 
 layoutDirection
 
 locale
 
 maximized
 
 maximumHeight
 
 maximumSize
 
 maximumWidth
 
 minimized
 
 minimumHeight
 
 minimumSize
 
 minimumSizeHint
 
 minimumWidth
 
 modal
 
 mouseTracking
 
 normalGeometry
 
 palette
 
 pos
 
 rect
 
 size
 
 sizeHint
 
 sizeIncrement
 
 sizePolicy
 
 statusTip
 
 styleSheet
 
 toolTip
 
 updatesEnabled
 
 visible
 
 whatsThis
 
 width
 
 windowFilePath
 
 windowFlags
 
 windowIcon
 
 windowIconText
 
 windowModality
 
 windowModified
 
 windowOpacity
 
 windowTitle
 
 x
 
 y
 
- Properties inherited from QObject
 objectName
 

Friends

class QAbstractSpinBox
 
class QDateTimeEdit
 

Additional Inherited Members

- Public Typedefs inherited from QWidget
using RenderFlags = QFlags< RenderFlag >
 
- Static Public Methods inherited from QWidget
static QWidget * createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
static QWidget * find (WId id)
 
static QWidget * keyboardGrabber ()
 
static QWidget * mouseGrabber ()
 
static void setTabOrder (QWidget *firstWidget, QWidget *secondWidget)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 

Detailed Description

The QLineEdit widget is a single line text edit widget. A line edit allows the user to edit plain text with standard editing operations like undo, redo, cut, copy, and paste. The QTextEdit class is very similar to this one however it allows multi line and rich text editing.

Notifications

When the text changes either by calling setText() or the user typing, the textChanged() signal will be emitted. When the cursor is moved the cursorPositionChanged() signal is emitted and when the Return or Enter key are pressed the returnPressed() signal is emitted.

When editing is finished, either because the line edit has lost focus or Return/Enter was pressed, then the editingFinished() signal will be emitted. If there is a validator set on the line edit these signals will only be emitted if the validator returns QValidator::Acceptable.

Shortcuts

The default shortcuts or key bindings are described below. The line edit widget also provides a context menu which contains some of these editing options. Any other key sequence that represents a valid character will cause the character to be inserted into the line edit.

KeypressAction
Left ArrowMoves the cursor one character to the left.
Shift+Left ArrowMoves and selects text one character to the left.
Right ArrowMoves the cursor one character to the right.
Shift+Right ArrowMoves and selects text one character to the right.
HomeMoves the cursor to the beginning of the line.
EndMoves the cursor to the end of the line.
BackspaceDeletes the character to the left of the cursor.
Ctrl+BackspaceDeletes the word to the left of the cursor.
DeleteDeletes the character to the right of the cursor.
Ctrl+DeleteDeletes the word to the right of the cursor.
Ctrl+ASelect all.
Ctrl+CCopies the selected text to the clipboard.
Ctrl+InsertCopies the selected text to the clipboard.
Ctrl+KDeletes to the end of the line.
Ctrl+VPastes the clipboard text into line edit.
Shift+InsertPastes the clipboard text into line edit.
Ctrl+XDeletes the selected text and copies it to the clipboard.
Shift+DeleteDeletes the selected text and copies it to the clipboard.
Ctrl+ZUndoes the last operation.
Ctrl+YRedoes the last undone operation.

Styles

Screenshot of a Windows XP style line edit Line edit shown in the Windows XP widget style.
Screenshot of a Mac OS X style line edit Line edit shown in the Mac OS X widget style.
Screenshot of a Fusion style line edit Line edit shown in the Fusion widget style.
See also
QTextEdit, QLabel, QComboBox

Member Enumeration Documentation

This enum describes how a line edit should display the action widgets.

ConstantValueDescription
QLineEdit::LeadingPosition 0 Widget is displayed to the left of the text when using layout direction Qt::LeftToRight or to the right when using Qt::RightToLeft, respectively.
QLineEdit::TrailingPosition 1 Widget is displayed to the right of the text when using layout direction Qt::LeftToRight or to the left when using Qt::RightToLeft, respectively.
See also
addAction(), removeAction(), QWidget::layoutDirection

This enum type describes how a line edit should display its contents.

ConstantValueDescription
QLineEdit::Normal0 Display characters as they are entered, this is the default.
QLineEdit::NoEcho1 Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret.
QLineEdit::Password2 Display asterisks instead of the characters actually entered.
QLineEdit::PasswordEchoOnEdit3 Display characters as they are entered while editing otherwise display asterisks.
See also
setEchoMode(), echoMode()

Constructor & Destructor Documentation

QLineEdit::QLineEdit ( QWidget parent = nullptr)
explicit

Constructs a line edit with no text. The parent argument is sent to the QWidget constructor. The maximum text length is set to 32767 characters.

See also
setText(), setMaxLength()
QLineEdit::QLineEdit ( const QString contents,
QWidget parent = nullptr 
)
explicit

Constructs a line edit containing the text contents. The parent and argument is sent to the QWidget constructor. The cursor position is set to the end of the line and the maximum text length to 32767 characters.

See also
text(), setMaxLength()
QLineEdit::~QLineEdit ( )

Destroys the line edit.

Method Documentation

QAction * QLineEdit::addAction ( const QIcon icon,
ActionPosition  position 
)

Adds the icon to the list of existing actions available for this line edit. The location of the given action is added at the specified position.

void QWidget::addAction ( QAction action)
using

Appends action to the list of existing actions available for this widget. A QAction list is typically used to create a context QMenu, however it can be represented in different ways depending on the widget.

A QWidget should only have one of each action. Adding an action which already exists will not cause the same action to be in the widget multiple times. The ownership of action is not transferred to this QWidget.

See also
removeAction(), insertAction(), actions(), QMenu
void QLineEdit::addAction ( QAction action,
ActionPosition  position 
)

Add the action to the list of existing actions available for this line edit. The location of the given action is added at the specified position.

Qt::Alignment QLineEdit::alignment ( ) const

Returns the value of the alignment property.

void QLineEdit::backspace ( )

If no text is selected, this method 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.

See also
del()
void QLineEdit::changeEvent ( QEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::changeEvent()

void QLineEdit::clear ( )
slot

Clears the contents of the line edit.

See also
setText(), insert()
QCompleter * QLineEdit::completer ( ) const

Returns the current QCompleter.

See also
setCompleter()
void QLineEdit::contextMenuEvent ( QContextMenuEvent event)
overrideprotectedvirtual

Shows a context menu. The event parameter is used to obtain the position where the mouse cursor was when the event was generated.

If you do not want the line edit to have a context menu, you can set its contextMenuPolicy to Qt::NoContextMenu. If you want to customize the context menu, reimplement this method. If you want to extend the standard context menu, reimplement this function, call createStandardContextMenu() and extend the menu returned.

void LineEdit::contextMenuEvent(QContextMenuEvent *event) {
menu->addAction(tr("My Menu Item"));
menu->exec(event->globalPos());
delete menu;
}
See also
setContextMenuPolicy()

Reimplemented from QWidget::contextMenuEvent()

void QLineEdit::copy ( )
slot

Copies the selected text to the clipboard when the echoMode() is set to EchoMode::Normal.

See also
cut(), paste()
QMenu * QLineEdit::createStandardContextMenu ( )

This method creates the standard context menu which is shown when the user clicks on the line edit with the right mouse button. It is called from the default contextMenuEvent() handler. The popup menu's ownership is transferred to the caller.

void QLineEdit::cursorBackward ( bool  mark,
int  steps = 1 
)

Moves the cursor back steps characters. If mark is true each character moved over is added to the selection. If mark is false the selection is cleared.

See also
cursorForward()
void QLineEdit::cursorForward ( bool  mark,
int  steps = 1 
)

Moves the cursor forward steps characters. If mark is true each character moved over is added to the selection. If mark is false the selection is cleared.

See also
cursorBackward()
Qt::CursorMoveStyle QLineEdit::cursorMoveStyle ( ) const

Returns the value of the cursorMoveStyle property.

int QLineEdit::cursorPosition ( ) const

Returns the value of the cursorPosition property.

int QLineEdit::cursorPositionAt ( const QPoint pos)

Returns the cursor position under the point pos.

void QLineEdit::cursorPositionChanged ( int  oldValue,
int  newValue 
)
signal

This signal is emitted whenever the cursor moves. The previous position is given by oldValue and the new position by newValue.

See also
setCursorPosition(), cursorPosition()
QRect QLineEdit::cursorRect ( ) const
protected

Returns a rectangle that includes the line edit cursor.

void QLineEdit::cursorWordBackward ( bool  mark)

Moves the cursor one word backward. If mark is true the word is also selected.

See also
cursorWordForward()
void QLineEdit::cursorWordForward ( bool  mark)

Moves the cursor one word forward. If mark is true the word is also selected.

See also
cursorWordBackward()
void QLineEdit::cut ( )
slot

Copies the selected text to the clipboard and deletes it when echoMode() is set to EchoMode::Normal. If the current validator disallows deleting the selected text, cut() will copy without deleting.

See also
copy(), paste(), setValidator()
void QLineEdit::del ( )

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.

See also
backspace()
void QLineEdit::deselect ( )

Deselects any selected text.

See also
setSelection(), selectAll()
QString QLineEdit::displayText ( ) const

Returns the value of the displayText property.

bool QLineEdit::dragEnabled ( ) const

Returns the value of the property.

void QLineEdit::dragEnterEvent ( QDragEnterEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::dragEnterEvent()

void QLineEdit::dragLeaveEvent ( QDragLeaveEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::dragLeaveEvent()

void QLineEdit::dragMoveEvent ( QDragMoveEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::dragMoveEvent()

void QLineEdit::dropEvent ( QDropEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::dropEvent()

EchoMode QLineEdit::echoMode ( ) const

Returns the value of the echoMode property.

void QLineEdit::editingFinished ( )
signal

This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. If there is a validator() or inputMask() set on the line edit and enter/return is pressed, the editingFinished() signal will only be emitted if the input matches the inputMask() and the validator() returns QValidator::Acceptable.

void QLineEdit::end ( bool  mark)

Moves the text cursor to the end of the line unless it is already there. If mark is true text is selected towards the last position, otherwise any selected text is unselected if the cursor is moved.

See also
home()
bool QLineEdit::event ( QEvent event)
override

Reimplemented from QWidget::event()

void QLineEdit::focusInEvent ( QFocusEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::focusInEvent()

void QLineEdit::focusOutEvent ( QFocusEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::focusOutEvent()

void QLineEdit::getTextMargins ( int *  left,
int *  top,
int *  right,
int *  bottom 
) const

Returns the widget's text margins for left, top, right, and bottom.

See also
setTextMargins()
bool QLineEdit::hasAcceptableInput ( ) const

Returns the value of the acceptableInput property.

bool QLineEdit::hasFrame ( ) const

Returns the value of the frame property.

bool QLineEdit::hasSelectedText ( ) const

Returns the value of the hasSelectedText property.

void QLineEdit::home ( bool  mark)

Moves the text cursor to the beginning of the line unless it is already there. If mark is true, text is selected towards the first position, otherwise any selected text is unselected if the cursor is moved.

See also
end()
void QLineEdit::initStyleOption ( QStyleOptionFrame option) const
protected

Initialize option with the values from this QLineEdit. This method is useful for subclasses when they need a QStyleOptionFrame but do not want to fill in all the information themselves.

See also
QStyleOption::initFrom()
QString QLineEdit::inputMask ( ) const

Returns the value for the inputMask property.

See also
setInputMask()
void QLineEdit::inputMethodEvent ( QInputMethodEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::inputMethodEvent()

QVariant QLineEdit::inputMethodQuery ( Qt::InputMethodQuery  query) const
overridevirtual

Reimplemented from QWidget::inputMethodQuery()

void QLineEdit::insert ( const QString newText)

Deletes any selected text, inserts newText and validates the result. If the result is invalid this method does nothing.

See also
setText(), clear()
bool QLineEdit::isClearButtonEnabled ( ) const

Returns true if the clearButtonEnabled property is enabled, otherwise returns false.

bool QLineEdit::isModified ( ) const

Returns the value of the modified property.

bool QLineEdit::isReadOnly ( ) const

Returns the value of the readOnly property.

bool QLineEdit::isRedoAvailable ( ) const

Returns the value of the redoAvailable property.

bool QLineEdit::isUndoAvailable ( ) const

Returns the value of the undoAvailable property.

void QLineEdit::keyPressEvent ( QKeyEvent event)
overrideprotectedvirtual

Converts the given key press event into a line edit action. If Return or Enter is pressed and the current text is valid (or can be made valid by the validator), the signal returnPressed() is emitted.

The default key bindings are listed in the class detailed description.

Reimplemented from QWidget::keyPressEvent()

int QLineEdit::maxLength ( ) const

Returns the value of the maxLength property.

QSize QLineEdit::minimumSizeHint ( ) const
overridevirtual

Returns a minimum size for the line edit. The width returned is enough for at least one character.

Reimplemented from QWidget::minimumSizeHint()

void QLineEdit::mouseDoubleClickEvent ( QMouseEvent event)
overrideprotectedvirtual
void QLineEdit::mouseMoveEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mouseMoveEvent()

void QLineEdit::mousePressEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mousePressEvent()

void QLineEdit::mouseReleaseEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mouseReleaseEvent()

void QLineEdit::paintEvent ( QPaintEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::paintEvent()

void QLineEdit::paste ( )
slot

Inserts the clipboard's text at the cursor position, deleting any selected text, providing the line edit is not read-only. If the end result would not be acceptable to the current validator then this method does nothing.

See also
copy(), cut()
QString QLineEdit::placeholderText ( ) const

Returns the value of the placeholderText property.

void QLineEdit::redo ( )
slot

Redoes the last operation if redo is available.

void QLineEdit::returnPressed ( )
signal

This signal is emitted when the Return or Enter key is pressed. If there is a validator() or inputMask() set on the line edit, the returnPressed() signal will only be emitted if the input matches the inputMask() and the validator() returns QValidator::Acceptable.

void QLineEdit::selectAll ( )
slot

Selects all the text and moves the cursor to the end. This is useful when a default value has been inserted. If the user types before clicking on the widget the default selected text will be deleted.

See also
setSelection(), deselect()
QString QLineEdit::selectedText ( ) const

Returns the value of the property.

void QLineEdit::selectionChanged ( )
signal

This signal is emitted when the selection changes.

See also
hasSelectedText(), selectedText()
int QLineEdit::selectionStart ( ) const

Returns the index of the first selected character in the line edit or -1 if no text is selected.

See also
selectedText()
void QLineEdit::setAlignment ( Qt::Alignment  flag)

Sets the value of the alignment property.

void QLineEdit::setClearButtonEnabled ( bool  enable)

Sets the value of the clearButtonEnabled property.

void QLineEdit::setCompleter ( QCompleter completer)

Sets this line edit to provide auto completion using completer. The completion mode is set using QCompleter::setCompletionMode(). If the value for completer is a nullptr this method removes the current QCompleter.

To use a QCompleter with a QValidator or QLineEdit::inputMask, you need to ensure that the model provided to QCompleter contains valid entries. You can use the QSortFilterProxyModel to ensure that the QCompleter's model contains only valid entries.

See also
completer(), QCompleter
void QLineEdit::setCursorMoveStyle ( Qt::CursorMoveStyle  style)

Sets the value of the cursorMoveStyle property to style.

void QLineEdit::setCursorPosition ( int  )

Sets the value of the cursorPosition property.

void QLineEdit::setDragEnabled ( bool  enable)

Sets the value of the dragEnabled property to enable.

void QLineEdit::setEchoMode ( EchoMode  )

Sets the value of the echoMode property.

void QLineEdit::setFrame ( bool  )

Sets the value of the frame property.

void QLineEdit::setInputMask ( const QString inputMask)

Sets the inputMask property to inputMask. To unset the mask and return to normal QLineEdit operation pass an empty string or call this method with no arguments.

Refer to the inputMask property for examples.

See also
QLineEdit::inputMask()
void QLineEdit::setMaxLength ( int  )

Sets the value of the maxLength property.

void QLineEdit::setModified ( bool  )

Sets the value of the modified property.

void QLineEdit::setPlaceholderText ( const QString )

Sets the value of the placeholderText property.

void QLineEdit::setReadOnly ( bool  )

Sets the value of the readOnly property.

void QLineEdit::setSelection ( int  start,
int  length 
)

Selects text from position start and for length characters. Negative lengths are allowed.

See also
deselect(), selectAll(), selectedText()
void QLineEdit::setText ( const QString str)
slot

Sets the value of the text property to str.

void QLineEdit::setTextMargins ( const QMargins margins)

Sets the margins around the text inside the frame.

See also
textMargins()
void QLineEdit::setTextMargins ( int  left,
int  top,
int  right,
int  bottom 
)

Sets the margins around the text inside the frame to have the sizes left, top, right, and bottom.

See also
textMargins(), getTextMargins()
void QLineEdit::setValidator ( const QValidator validator)

Sets this line edit to check input using validator. This allows setting constraints on the text which may be entered. If the value for validator is a nullptr the current input QValidator is removed. The initial setting is to have no input QValidator.

See also
validator(), QIntValidator, QDoubleValidator, QRegularExpressionValidator
QSize QLineEdit::sizeHint ( ) const
overridevirtual

Returns a recommended size for the widget. The width returned, which is in pixels, is usually enough for about 15 to 20 characters.

Reimplemented from QWidget::sizeHint()

QString QLineEdit::text ( ) const

Returns the value of the text property.

void QLineEdit::textChanged ( const QString newText)
signal

This signal is emitted when the text changes. The newText argument is the new text. Unlike the textEdited() signal, this signal is emitted when the text is changed by the user typing or when the program calls setText().

void QLineEdit::textEdited ( const QString newText)
signal

This signal is emitted when the text is edited. The newText argument is the new text.

QMargins QLineEdit::textMargins ( ) const

Returns the text margins for the line edit widget.

See also
setTextMargins()
void QLineEdit::undo ( )
slot

Undoes the last operation if undo is available. Deselects any current selection and updates the selection start to the current cursor position.

const QValidator * QLineEdit::validator ( ) const

Returns a pointer to the current input validator or nullptr if no validator has been set.

See also
setValidator()

Property Documentation

QLineEdit::acceptableInput

This property holds whether the input satisfies the inputMask and the validator. By default this property is true.

See also
setInputMask(), setValidator()
PropertiesClass Methods
read hasAcceptableInput
QLineEdit::alignment

This property holds the alignment of the line edit. Both horizontal and vertical alignment is allowed here, Qt::AlignJustify will map to Qt::AlignLeft.

By default this property contains a combination of Qt::AlignLeft and Qt::AlignVCenter.

See also
Qt::Alignment
PropertiesClass Methods
read alignment
write setAlignment
QLineEdit::clearButtonEnabled

This property holds whether the line edit displays a clear button when it is not empty. If enabled the line edit displays a trailing clear button when it contains some text, otherwise the line edit does not show a clear button, which is the default.

See also
addAction(), removeAction()
PropertiesClass Methods
read isClearButtonEnabled
write setClearButtonEnabled
QLineEdit::cursorMoveStyle

This property holds the movement style of cursor in this line edit.

When this property is set to Qt::VisualMoveStyle, the line edit will use visual movement style. Pressing the left arrow key will always cause the cursor to move left, regardless of the text's writing direction. The same behavior applies to right arrow key.

When the property is Qt::LogicalMoveStyle (the default), within a LTR text block, increase cursor position when pressing left arrow key, decrease cursor position when pressing the right arrow key. If the text block is right to left, the opposite behavior applies.

PropertiesClass Methods
read cursorMoveStyle
write setCursorMoveStyle
QLineEdit::cursorPosition

This property holds the current cursor position for this line edit. Setting the cursor position causes a repaint when appropriate.

By default this property contains a value of 0.

PropertiesClass Methods
read cursorPosition
write setCursorPosition
QLineEdit::displayText

This property holds the displayed text.

If echoMode is set to EchoMode::Normal displayText and text() will contain the same value. If EchoMode is set to EchoMode::Password or EchoMode::PasswordEchoOnEdit then displayText will contain a string of asterisks. If EchoMode is set to EchoMode::NoEcho then displayText contains an empty string.

By default this property contains an empty string.

See also
setEchoMode(), text(), EchoMode
PropertiesClass Methods
read displayText
QLineEdit::dragEnabled

This property holds whether the line edit starts a drag if the user presses and moves the mouse on some selected text. Dragging is disabled by default.

PropertiesClass Methods
read dragEnabled
write setDragEnabled
QLineEdit::echoMode

This property holds the echo mode for this line edit.

The echo mode determines how the text entered in the line edit is displayed (or echoed) to the user. The most common setting is EchoMode::Normal where the text entered by the user is displayed exactly as they typed it.

QLineEdit also supports modes that allow the entered text to be hidden. The widget's display and the ability to copy or drag the text is affected by this setting.

By default this property is set to EchoMode::Normal.

See also
EchoMode, displayText()
PropertiesClass Methods
read echoMode
write setEchoMode
QLineEdit::frame

This property holds whether the line edit draws itself with a frame. If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame.

PropertiesClass Methods
read hasFrame
write setFrame
QLineEdit::hasSelectedText

This property holds whether there is any text selected. Returns true if some or all of the text has been selected by the user, otherwise returns false.

By default this property is false.

See also
selectedText()
PropertiesClass Methods
read hasSelectedText
QLineEdit::inputMask

This property holds the value for the input mask. The table below shows the characters which can be used to define an input mask. A space means a character is permitted but not required.

CharacterDescription
AASCII alphabetic character required. A-Z, a-z.
aASCII alphabetic character permitted but not required.
NASCII alphanumeric character required. A-Z, a-z, 0-9.
nASCII alphanumeric character permitted but not required.
XAny character required.
xAny character permitted but not required.
9ASCII digit required. 0-9.
0ASCII digit permitted but not required.
DASCII digit required. 1-9.
dASCII digit permitted but not required (1-9).
#ASCII digit or plus/minus sign permitted but not required.
HHexadecimal character required. A-F, a-f, 0-9.
hHexadecimal character permitted but not required.
BBinary character required. 0-1.
bBinary character permitted but not required.
>All following alphabetic characters are uppercased.
<All following alphabetic characters are lowercased.
!Switch off case conversion.
\Use \ to escape the special characters listed above to use them as separators.

The mask can end with a semicolon followed by one character. This character will be used instead of displaying a "space". The special blank characters are always removed from the text after editing.

MaskNotes
000.000.000.000;_ IP address, blanks are denoted with an underscore
HH:HH:HH:HH:HH:HH;_ MAC address, blanks are denoted with a pound sign
0000-00-00 ISO Date, blanks are denoted with a space
>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# License number, blanks are denoted with a dash and all alphabetic characters are converted to uppercase
See also
maxLength, setValidator()
PropertiesClass Methods
read inputMask
write setInputMask
QLineEdit::maxLength

This property holds the maximum permitted length of the text.

If the text is too long, it is truncated at the limit. If truncation occurs any selected text will be unselected, the cursor position is set to 0 and the first part of the string is shown. If the line edit has an input mask, the mask defines the maximum string length.

By default this property contains a value of 32767.

See also
inputMask
PropertiesClass Methods
read maxLength
write setMaxLength
QLineEdit::modified

This property holds 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 has not entered any text), insert the default value.

Calling setText() resets the modified flag to false.

PropertiesClass Methods
read isModified
write setModified
designable true
QLineEdit::placeholderText

This property holds the line edit's placeholder text. Setting this property makes the line edit display a grayed-out placeholder text as long as the text() is empty and the widget does not have focus.

By default this property contains an empty string.

See also
text()
PropertiesClass Methods
read placeholderText
write setPlaceholderText
QLineEdit::readOnly

This property holds 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 set to Normal), but can not edit it. QLineEdit does not show a cursor in read only mode.

By default this property is false.

See also
setEnabled()
PropertiesClass Methods
read isReadOnly
write setReadOnly
QLineEdit::redoAvailable

This property holds whether redo is available. Redo becomes available once the user has performed one or more undo operations on text in the line edit.

By default this property is false.

PropertiesClass Methods
read isRedoAvailable
QLineEdit::selectedText

This property holds the selected text. If there is no selected text this property's value is an empty string. By default this property contains an empty string.

See also
hasSelectedText()
PropertiesClass Methods
read selectedText
QLineEdit::text

This property holds the line edit's text.

Setting this property clears the selection, clears the undo/redo history, moves the cursor to the end of the line and resets the modified property to false. The text is not validated when inserted with setText(). The text is truncated to maxLength() length.

By default this property contains an empty string.

See also
insert(), clear()
PropertiesClass Methods
read text
write setText
notify textChanged
user true
QLineEdit::undoAvailable

This property holds whether undo is available. Undo becomes available once the user has modified the text in the line edit. By default this property is false.

PropertiesClass Methods
read isUndoAvailable