Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Functions | Properties | Friends | List of all members
QLineEdit Class Reference

The QLineEdit widget is a one-line text editor. More...

#include <qlineedit.h>

Inheritance diagram for QLineEdit:
QWidget QObject QPaintDevice QExpandingLineEdit QFileDialogLineEdit

Public Types

enum  EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit }
 This enum type describes how a line edit should display its contents. More...
 
- Public Types inherited from QWidget
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
 This enum describes how to render the widget when calling QWidget::render(). More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 

Public Slots

void clear ()
 Clears the contents of the line edit. More...
 
void copy () const
 Copies the selected text to the clipboard, if there is any, and if echoMode() is Normal . More...
 
void cut ()
 Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode() is Normal . More...
 
void paste ()
 Inserts the clipboard's text at the cursor position, deleting any selected text, providing the line edit is not read-only. More...
 
void redo ()
 Redoes the last operation if redo is available. More...
 
void selectAll ()
 Selects all the text (i.e. More...
 
void setText (const QString &)
 
void undo ()
 Undoes the last operation if undo is available. More...
 
- Public Slots inherited from QWidget
bool close ()
 Closes this widget. More...
 
void hide ()
 Hides the widget. More...
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack. More...
 
void raise ()
 Raises this widget to the top of the parent widget's stack. More...
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden. More...
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events. More...
 
void setEnabled (bool)
 
void setFocus ()
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden). More...
 
QT_MOC_COMPAT void setShown (bool shown)
 Use setVisible(shown) instead. More...
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void show ()
 Shows the widget and its child widgets. More...
 
void showFullScreen ()
 Shows the widget in full-screen mode. More...
 
void showMaximized ()
 Shows the widget maximized. More...
 
void showMinimized ()
 Shows the widget minimized, as an icon. More...
 
void showNormal ()
 Restores the widget after it has been maximized or minimized. More...
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void cursorPositionChanged (int, int)
 This signal is emitted whenever the cursor moves. More...
 
void editingFinished ()
 This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. More...
 
void returnPressed ()
 This signal is emitted when the Return or Enter key is pressed. More...
 
void selectionChanged ()
 This signal is emitted whenever the selection changes. More...
 
void textChanged (const QString &)
 This signal is emitted whenever the text changes. More...
 
void textEdited (const QString &)
 This signal is emitted whenever the text is edited. More...
 
- Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

Qt::Alignment alignment () const
 
void backspace ()
 If no text is selected, deletes the character to the left of the text cursor and moves the cursor one position to the left. More...
 
QCompletercompleter () const
 Returns the current QCompleter that provides completions. More...
 
QMenucreateStandardContextMenu ()
 This function creates the standard context menu which is shown when the user clicks on the line edit with the right mouse button. More...
 
void cursorBackward (bool mark, int steps=1)
 Moves the cursor back steps characters. More...
 
void cursorForward (bool mark, int steps=1)
 Moves the cursor forward steps characters. More...
 
Qt::CursorMoveStyle cursorMoveStyle () const
 
int cursorPosition () const
 
int cursorPositionAt (const QPoint &pos)
 Returns the cursor position under the point pos. More...
 
void cursorWordBackward (bool mark)
 Moves the cursor one word backward. More...
 
void cursorWordForward (bool mark)
 Moves the cursor one word forward. More...
 
void del ()
 If no text is selected, deletes the character to the right of the text cursor. More...
 
void deselect ()
 Deselects any selected text. More...
 
QString displayText () const
 
bool dragEnabled () const
 
EchoMode echoMode () const
 
void end (bool mark)
 Moves the text cursor to the end of the line unless it is already there. More...
 
bool event (QEvent *)
 Reimplemented Function More...
 
void getTextMargins (int *left, int *top, int *right, int *bottom) const
 Returns the widget's text margins for left, top, right, and bottom. More...
 
bool hasAcceptableInput () const
 
bool hasFrame () const
 
bool hasSelectedText () const
 
void home (bool mark)
 Moves the text cursor to the beginning of the line unless it is already there. More...
 
QString inputMask () const
 
QVariant inputMethodQuery (Qt::InputMethodQuery) const
 em>Reimplemented Function More...
 
void insert (const QString &)
 Deletes any selected text, inserts newText, and validates the result. More...
 
bool isModified () const
 
bool isReadOnly () const
 
bool isRedoAvailable () const
 
bool isUndoAvailable () const
 
int maxLength () const
 
QSize minimumSizeHint () const
 Returns a minimum size for the line edit. More...
 
QString placeholderText () const
 
 QLineEdit (QWidget *parent=0)
 Constructs a line edit with no text. More...
 
 QLineEdit (const QString &, QWidget *parent=0)
 Constructs a line edit containing the text contents. More...
 
QString selectedText () const
 
int selectionStart () const
 selectionStart() returns the index of the first selected character in the line edit or -1 if no text is selected. More...
 
void setAlignment (Qt::Alignment flag)
 
void setCompleter (QCompleter *completer)
 Sets this line edit to provide auto completions from the completer, c. More...
 
void setCursorMoveStyle (Qt::CursorMoveStyle style)
 Sets the movement style for the cursor in the line edit to the given style. More...
 
void setCursorPosition (int)
 
void setDragEnabled (bool b)
 
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, int)
 Selects text from position start and for length characters. More...
 
void 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. More...
 
void setTextMargins (const QMargins &margins)
 Sets the margins around the text inside the frame. More...
 
void setValidator (const QValidator *)
 Sets this line edit to only accept input that the validator, v, will accept. More...
 
QSize sizeHint () const
 Returns a recommended size for the widget. More...
 
QString text () const
 
QMargins textMargins () const
 Returns the widget's text margins. More...
 
const QValidatorvalidator () const
 Returns a pointer to the current input validator, or 0 if no validator has been set. More...
 
 ~QLineEdit ()
 Destroys the line edit. More...
 
- Public Functions inherited from QWidget
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions. More...
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window. More...
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions. More...
 
void addActions (QList< QAction *> actions)
 Appends the actions actions to this widget's list of actions. More...
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents. More...
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget. More...
 
QSize baseSize () const
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system. More...
 
QWidgetchildAt (const QPoint &p) const
 Returns the visible child widget at point p in the widget's own coordinate system. More...
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 Takes keyboard input focus from the widget. More...
 
void clearMask ()
 Removes any mask set by setMask(). More...
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins. More...
 
QRect contentsRect () const
 Returns the area inside the widget's margins. More...
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void createWinId ()
 
QCursor cursor () const
 
int devType () const
 
WId effectiveWinId () const
 Returns the effective window system identifier of the widget, i. More...
 
void ensurePolished () const
 Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette). More...
 
Qt::FocusPolicy focusPolicy () const
 
QWidgetfocusProxy () const
 Returns the focus proxy, or 0 if there is no focus proxy. More...
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on. More...
 
const QFontfont () const
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font. More...
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font. More...
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role. More...
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 Returns the widget's contents margins for left, top, right, and bottom. More...
 
HDC getDC () const
 Returns the window system handle of the widget, for low-level access. More...
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
void grabMouse (const QCursor &)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. More...
 
QGraphicsEffectgraphicsEffect () const
 The graphicsEffect function returns a pointer to the widget's graphics effect. More...
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0. More...
 
bool hasFocus () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int) const
 Returns the preferred height for this widget, given the width w. More...
 
QInputContextinputContext ()
 This function returns the QInputContext for this widget. More...
 
Qt::InputMethodHints inputMethodHints () const
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before. More...
 
void insertActions (QAction *before, QList< QAction *> actions)
 Inserts the actions actions to this widget's list of actions, before the action before. More...
 
WId internalWinId () const
 Returns the window system identifier of the widget, or 0 if the widget is not created yet. More...
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child, and both widgets are within the same window; otherwise returns false. More...
 
bool isEnabled () const
 
bool isEnabledTo (QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false. More...
 
bool isEnabledToTLW () const
 This function is deprecated. More...
 
bool isFullScreen () const
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false. More...
 
bool isLeftToRight () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isRightToLeft () const
 
bool isTopLevel () const
 Use isWindow() instead. More...
 
bool isVisible () const
 
bool isVisibleTo (QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false. More...
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false. More...
 
bool isWindowModified () const
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed. More...
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
Qt::HANDLE macCGHandle () const
 Returns the CoreGraphics handle of the widget. More...
 
Qt::HANDLE macQDHandle () const
 Returns the QuickDraw handle of the widget. More...
 
QPoint mapFrom (QWidget *, const QPoint &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system. More...
 
QPoint mapFromGlobal (const QPoint &) const
 Translates the global screen coordinate pos to widget coordinates. More...
 
QPoint mapFromParent (const QPoint &) const
 Translates the parent widget coordinate pos to widget coordinates. More...
 
QPoint mapTo (QWidget *, const QPoint &) const
 Translates the widget coordinate pos to the coordinate system of parent. More...
 
QPoint mapToGlobal (const QPoint &) const
 Translates the widget coordinate pos to global screen coordinates. More...
 
QPoint mapToParent (const QPoint &) const
 Translates the widget coordinate pos to a coordinate in the parent widget. More...
 
QRegion mask () const
 Returns the mask currently set on a widget. More...
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (int x, int y)
 This corresponds to move(QPoint(x, y)). More...
 
void move (const QPoint &)
 
QWidgetnativeParentWidget () const
 Returns the native parent for this widget, i. More...
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain. More...
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system. More...
 
void overrideWindowState (Qt::WindowStates state)
 
QPaintEnginepaintEngine () const
 Returns the widget's paint engine. More...
 
const QPalettepalette () const
 
QWidgetparentWidget () const
 Returns the parent of this widget, or 0 if it does not have any parent widget. More...
 
QPoint pos () const
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain. More...
 
 QWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a widget which is a child of parent, with widget flags set to f. More...
 
QRect rect () const
 
void releaseDC (HDC) const
 Releases the HDC hdc acquired by a previous call to getDC(). More...
 
void releaseKeyboard ()
 Releases the keyboard grab. More...
 
void releaseMouse ()
 Releases the mouse grab. More...
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system. More...
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions. More...
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the sourceRegion of this widget into the target using renderFlags to determine how to render. More...
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the widget into the painter's QPainter::device(). More...
 
void repaint (int x, int y, int w, int h)
 This version repaints a rectangle (x, y, w, h) inside the widget. More...
 
void repaint (const QRect &)
 This version repaints a rectangle rect inside the widget. More...
 
void repaint (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void resize (int w, int h)
 This corresponds to resize(QSize(w, h)). More...
 
void resize (const QSize &)
 
bool restoreGeometry (const QByteArray &geometry)
 Restores the geometry and state top-level widgets stored in the byte array geometry. More...
 
QByteArray saveGeometry () const
 Saves the current geometry and state for top-level widgets. More...
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward. More...
 
void scroll (int dx, int dy, const QRect &)
 This version only scrolls r and does not move the children of the widget. More...
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. More...
 
void setAutoFillBackground (bool enabled)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role. More...
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 This corresponds to setBaseSize(QSize(basew, baseh)). More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom. More...
 
void setContentsMargins (const QMargins &margins)
 The setContentsMargins function sets the margins around the widget's contents. More...
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &)
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths. More...
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking. More...
 
void setFixedSize (int w, int h)
 Sets the width of the widget to w and the height to h. More...
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights. More...
 
void setFocus (Qt::FocusReason reason)
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w. More...
 
void setFont (const QFont &)
 Use the single-argument overload instead. More...
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role. More...
 
void setGeometry (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setGeometry(QRect(x, y, w, h)). More...
 
void setGeometry (const QRect &)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 The setGraphicsEffect function is for setting the widget's graphics effect. More...
 
void setInputContext (QInputContext *)
 This function sets the input context context on this widget. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. More...
 
void setMask (const QRegion &)
 Causes only the parts of the widget which overlap region to be visible. More...
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This function corresponds to setMaximumSize(QSize(maxw, maxh)). More...
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This function corresponds to setMinimumSize(QSize(minw, minh)). More...
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &)
 Use the single-argument overload instead. More...
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags. More...
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This function also takes widget flags, f as an argument. More...
 
void setShortcutAutoRepeat (int id, bool enable=true)
 If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled. More...
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled. More...
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 Sets the x (width) size increment to w and the y (height) size increment to h. More...
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width. More...
 
void setStatusTip (const QString &)
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style. More...
 
void setToolTip (const QString &)
 
void setUpdatesEnabled (bool enable)
 
void setupUi (QWidget *widget)
 Sets up the user interface for the specified widget. More...
 
void setWhatsThis (const QString &)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags type)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowIconText (const QString &)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &)
 Sets the window's role to role. More...
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState. More...
 
void setWindowSurface (QWindowSurface *surface)
 Sets the window surface to be the surface specified. More...
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack. More...
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false. More...
 
QString toolTip () const
 
QWidgettopLevelWidget () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false. More...
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type. More...
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (int x, int y, int w, int h)
 This version updates a rectangle (x, y, w, h) inside the widget. More...
 
void update (const QRect &)
 This version updates a rectangle rect inside the widget. More...
 
void update (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry. More...
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur. More...
 
QString whatsThis () const
 
int width () const
 
QWidgetwindow () const
 Returns the window for this widget, i.e. More...
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e. More...
 
QIcon windowIcon () const
 
QString windowIconText () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 Returns the window's role, or an empty string. More...
 
Qt::WindowStates windowState () const
 Returns the current window state. More...
 
QWindowSurfacewindowSurface () const
 Returns the QWindowSurface this widget will be drawn into. More...
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 Returns the window type of this widget. More...
 
WId winId () const
 Returns the window system identifier of the widget. More...
 
int x () const
 
const QX11Infox11Info () const
 Returns information about the configuration of the X display used to display the widget. More...
 
Qt::HANDLE x11PictureHandle () const
 Returns the X11 Picture handle of the widget for XRender support. More...
 
int y () const
 
 ~QWidget ()
 Destroys the widget. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Protected Functions

void changeEvent (QEvent *)
 Reimplemented Function More...
 
void contextMenuEvent (QContextMenuEvent *)
 Shows the standard context menu created with createStandardContextMenu(). More...
 
QRect cursorRect () const
 Returns a rectangle that includes the lineedit cursor. More...
 
void dragEnterEvent (QDragEnterEvent *)
 em>Reimplemented Function More...
 
void dragLeaveEvent (QDragLeaveEvent *e)
 em>Reimplemented Function More...
 
void dragMoveEvent (QDragMoveEvent *e)
 em>Reimplemented Function More...
 
void dropEvent (QDropEvent *)
 This event handler is called when the drag is dropped on this widget. More...
 
void focusInEvent (QFocusEvent *)
 em>Reimplemented Function More...
 
void focusOutEvent (QFocusEvent *)
 em>Reimplemented Function More...
 
void initStyleOption (QStyleOptionFrame *option) const
 Initialize option with the values from this QLineEdit. More...
 
void inputMethodEvent (QInputMethodEvent *)
 Reimplemented Function More...
 
void keyPressEvent (QKeyEvent *)
 Converts the given key press event into a line edit action. More...
 
void mouseDoubleClickEvent (QMouseEvent *)
 Reimplemented Function More...
 
void mouseMoveEvent (QMouseEvent *)
 Reimplemented Function More...
 
void mousePressEvent (QMouseEvent *)
 Reimplemented Function More...
 
void mouseReleaseEvent (QMouseEvent *)
 Reimplemented Function More...
 
void paintEvent (QPaintEvent *)
 em>Reimplemented Function More...
 
- Protected Functions inherited from QWidget
virtual void actionEvent (QActionEvent *)
 This event handler is called with the given event whenever the widget's actions are changed. More...
 
virtual void closeEvent (QCloseEvent *)
 This event handler is called with the given event when Qt receives a window close request for a top-level widget from the window system. More...
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window if window is 0, otherwise sets the widget's window to window. More...
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources. More...
 
virtual void enabledChange (bool)
 
virtual void enterEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter. More...
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual bool focusNextPrevChild (bool next)
 Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void fontChange (const QFont &)
 
virtual void hideEvent (QHideEvent *)
 This event handler can be reimplemented in a subclass to receive widget hide events. More...
 
virtual void keyReleaseEvent (QKeyEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive key release events for the widget. More...
 
virtual void languageChange ()
 
virtual void leaveEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter. More...
 
virtual bool macEvent (EventHandlerCallRef, EventRef)
 This special event handler can be reimplemented in a subclass to receive native Macintosh events. More...
 
int metric (PaintDeviceMetric) const
 Internal implementation of the virtual QPaintDevice::metric() function. More...
 
virtual void moveEvent (QMoveEvent *)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter. More...
 
virtual void paletteChange (const QPalette &)
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
virtual bool qwsEvent (QWSEvent *)
 This special event handler can be reimplemented in a subclass to receive native Qt for Embedded Linux events which are passed in the event parameter. More...
 
void resetInputContext ()
 This function can be called on the widget that currently has focus to reset the input method operating on it. More...
 
virtual void resizeEvent (QResizeEvent *)
 This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. More...
 
virtual void showEvent (QShowEvent *)
 This event handler can be reimplemented in a subclass to receive widget show events which are passed in the event parameter. More...
 
virtual void styleChange (QStyle &)
 
virtual void tabletEvent (QTabletEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive tablet events for the widget. More...
 
virtual void wheelEvent (QWheelEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive wheel events for the widget. More...
 
virtual void windowActivationChange (bool)
 
virtual bool winEvent (MSG *message, long *result)
 This special event handler can be reimplemented in a subclass to receive native Windows events which are passed in the message parameter. More...
 
virtual bool x11Event (XEvent *)
 This special event handler can be reimplemented in a subclass to receive native X11 events passed in the event parameter. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

bool acceptableInput
 whether the input satisfies the inputMask and the validator. More...
 
Qt::Alignment alignment
 the alignment of the line edit More...
 
Qt::CursorMoveStyle cursorMoveStyle
 the movement style of cursor in this line edit More...
 
int cursorPosition
 the current cursor position for this line edit More...
 
QString displayText
 the displayed text More...
 
bool dragEnabled
 whether the lineedit starts a drag if the user presses and moves the mouse on some selected text More...
 
EchoMode echoMode
 the line edit's echo mode More...
 
bool frame
 whether the line edit draws itself with a frame More...
 
bool hasSelectedText
 whether there is any text selected More...
 
QString inputMask
 The validation input mask. More...
 
int maxLength
 the maximum permitted length of the text More...
 
bool modified
 whether the line edit's contents has been modified by the user More...
 
QString placeholderText
 the line edit's placeholder text More...
 
bool readOnly
 whether the line edit is read only. More...
 
bool redoAvailable
 whether redo is available More...
 
QString selectedText
 the selected text More...
 
QString text
 the line edit's text More...
 
bool undoAvailable
 whether undo is available More...
 

Friends

class QAbstractSpinBox
 
class QAccessibleLineEdit
 

Additional Inherited Members

- Static Public Functions inherited from QWidget
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifer/handle id. More...
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input. More...
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input. More...
 
static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 Updates the widget's micro focus. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QPaintDevice
ushort painters
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QLineEdit widget is a one-line text editor.

A line edit allows the user to enter and edit a single line of plain text with a useful collection of editing functions, including undo and redo, cut and paste, and drag and drop.

By changing the echoMode() of a line edit, it can also be used as a "write-only" field, for inputs such as passwords.

The length of the text can be constrained to maxLength(). The text can be arbitrarily constrained using a validator() or an inputMask(), or both. When switching between a validator and an input mask on the same line edit, it is best to clear the validator or input mask to prevent undefined behavior.

A related class is QTextEdit which allows multi-line, rich text editing.

You can change the text with setText() or insert(). The text is retrieved with text(); the displayed text (which may be different, see EchoMode) is retrieved with displayText(). Text can be selected with setSelection() or selectAll(), and the selection can be cut(), copy()ied and paste()d. The text can be aligned with setAlignment().

When the text changes the textChanged() signal is emitted; when the text changes other than by calling setText() the textEdited() signal is emitted; when the cursor is moved the cursorPositionChanged() signal is emitted; and when the Return or Enter key is pressed the returnPressed() signal is emitted.

When editing is finished, either because the line edit lost focus or Return/Enter is pressed the editingFinished() signal is emitted.

Note that if there is a validator set on the line edit, the returnPressed()/editingFinished() signals will only be emitted if the validator returns QValidator::Acceptable.

By default, QLineEdits have a frame as specified by the Windows and Motif style guides; you can turn it off by calling setFrame(false).

The default key bindings are described below. The line edit also provides a context menu (usually invoked by a right mouse click) that presents some of these editing options.

Keypress Action
Left Arrow Moves the cursor one character to the left.
Shift+Left Arrow Moves and selects text one character to the left.
Right Arrow Moves the cursor one character to the right.
Shift+Right Arrow Moves and selects text one character to the right.
Home Moves the cursor to the beginning of the line.
End Moves the cursor to the end of the line.
Backspace Deletes the character to the left of the cursor.
Ctrl+Backspace Deletes the word to the left of the cursor.
Delete Deletes the character to the right of the cursor.
Ctrl+Delete Deletes the word to the right of the cursor.
Ctrl+A Select all.
Ctrl+C Copies the selected text to the clipboard.
Ctrl+Insert Copies the selected text to the clipboard.
Ctrl+K Deletes to the end of the line.
Ctrl+V Pastes the clipboard text into line edit.
Shift+Insert Pastes the clipboard text into line edit.
Ctrl+X Deletes the selected text and copies it to the clipboard.
Shift+Delete Deletes the selected text and copies it to the clipboard.
Ctrl+Z Undoes the last operation.
Ctrl+Y Redoes the last undone operation.

Any other key sequence that represents a valid character, will cause the character to be inserted into the line edit.

macintosh-lineedit.png
Screenshot of a Macintosh style line edit
A line edit shown in the Macintosh Style Widget Gallery{Macintosh widget style}.
windows-lineedit.png
Screenshot of a Windows XP style line edit
A line edit shown in the Windows XP Style Widget Gallery{Windows XP widget style}.
plastique-lineedit.png
Screenshot of a Plastique style line edit
A line edit shown in the Plastique Style Widget Gallery{Plastique widget style}.
See also
QTextEdit, QLabel, QComboBox, {fowler}{GUI Design Handbook: Field, Entry}, {Line Edits Example}

Definition at line 66 of file qlineedit.h.

Enumerations

◆ EchoMode

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

  • Normal Display characters as they are entered. This is the default.
  • NoEcho Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret.
  • Password Display asterisks instead of the characters actually entered.
  • PasswordEchoOnEdit Display characters as they are entered while editing otherwise display asterisks.
See also
setEchoMode() echoMode()
Enumerator
Normal 
NoEcho 
Password 
PasswordEchoOnEdit 

Definition at line 113 of file qlineedit.h.

Constructors and Destructors

◆ QLineEdit() [1/2]

QLineEdit::QLineEdit ( QWidget parent = 0)
explicit

Constructs a line edit with no text.

The maximum text length is set to 32767 characters.

The parent argument is sent to the QWidget constructor.

See also
setText(), setMaxLength()

Definition at line 280 of file qlineedit.cpp.

Referenced by QLineEdit().

281  : QWidget(*new QLineEditPrivate, parent,0)
282 {
283  Q_D(QLineEdit);
284  d->init(QString());
285 }
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ QLineEdit() [2/2]

QLineEdit::QLineEdit ( const QString contents,
QWidget parent = 0 
)
explicit

Constructs a line edit containing the text contents.

The cursor position is set to the end of the line and the maximum text length to 32767 characters.

The parent and argument is sent to the QWidget constructor.

See also
text(), setMaxLength()

Definition at line 298 of file qlineedit.cpp.

299  : QWidget(*new QLineEditPrivate, parent, 0)
300 {
301  Q_D(QLineEdit);
302  d->init(contents);
303 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ ~QLineEdit()

QLineEdit::~QLineEdit ( )

Destroys the line edit.

Definition at line 372 of file qlineedit.cpp.

373 {
374 }

Functions

◆ alignment()

Qt::Alignment QLineEdit::alignment ( ) const

Referenced by cursorPositionAt(), and setAlignment().

◆ backspace()

void QLineEdit::backspace ( )

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.

See also
del()

Definition at line 896 of file qlineedit.cpp.

897 {
898  Q_D(QLineEdit);
899  d->control->backspace();
900 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ changeEvent()

void QLineEdit::changeEvent ( QEvent ev)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2299 of file qlineedit.cpp.

Referenced by QExpandingLineEdit::changeEvent().

2300 {
2301  Q_D(QLineEdit);
2302  switch(ev->type())
2303  {
2306  update();
2307  break;
2308  case QEvent::FontChange:
2309  d->control->setFont(font());
2310  break;
2311  case QEvent::StyleChange:
2312  {
2313  QStyleOptionFrameV2 opt;
2314  initStyleOption(&opt);
2315  d->control->setPasswordCharacter(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this));
2316  }
2317  update();
2318  break;
2319  default:
2320  break;
2321  }
2323 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
const QPalette & palette() const
const char * styleHint(const QFontDef &request)
bool isEqual(ColorGroup cr1, ColorGroup cr2) const
Returns true (usually quickly) if color group cg1 is equal to cg2; otherwise returns false...
Definition: qpalette.cpp:1035
void initStyleOption(QStyleOptionFrame *option) const
Initialize option with the values from this QLineEdit.
Definition: qlineedit.cpp:104
The QStyleOptionFrameV2 class is used to describe the parameters necessary for drawing a frame in Qt ...
Definition: qstyleoption.h:134
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
const QFont & font() const
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ clear

void QLineEdit::clear ( )
slot

Clears the contents of the line edit.

See also
setText(), insert()

Definition at line 1443 of file qlineedit.cpp.

Referenced by QFileDialogPrivate::_q_enterDirectory(), inputMethodEvent(), and QScriptNewBreakpointWidget::onOkClicked().

1444 {
1445  Q_D(QLineEdit);
1447  d->control->clear();
1448 }
double d
Definition: qnumeric_p.h:62
void resetInputContext()
This function can be called on the widget that currently has focus to reset the input method operatin...
Definition: qwidget.cpp:522
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ completer()

QCompleter * QLineEdit::completer ( ) const

Returns the current QCompleter that provides completions.

Since
4.2

Definition at line 686 of file qlineedit.cpp.

Referenced by QComboBoxPrivate::matchFlags().

687 {
688  Q_D(const QLineEdit);
689  return d->control->completer();
690 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ contextMenuEvent()

void QLineEdit::contextMenuEvent ( QContextMenuEvent event)
protectedvirtual

Shows the standard context menu created with createStandardContextMenu().

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 function. 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;
}

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

See also
setContextMenuPolicy()

Reimplemented from QWidget.

Definition at line 2205 of file qlineedit.cpp.

2206 {
2207  if (QMenu *menu = createStandardContextMenu()) {
2208  menu->setAttribute(Qt::WA_DeleteOnClose);
2209  menu->popup(event->globalPos());
2210  }
2211 }
QMenu * createStandardContextMenu()
This function creates the standard context menu which is shown when the user clicks on the line edit ...
Definition: qlineedit.cpp:2223
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition: qevent.h:413

◆ copy

void QLineEdit::copy ( ) const
slot

Copies the selected text to the clipboard, if there is any, and if echoMode() is Normal .

See also
cut() paste()

Definition at line 1541 of file qlineedit.cpp.

Referenced by createStandardContextMenu(), and cut().

1542 {
1543  Q_D(const QLineEdit);
1544  d->control->copy();
1545 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ createStandardContextMenu()

QMenu * QLineEdit::createStandardContextMenu ( )

This function 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.

Definition at line 2223 of file qlineedit.cpp.

Referenced by contextMenuEvent().

2224 {
2225  Q_D(QLineEdit);
2226  QMenu *popup = new QMenu(this);
2227  popup->setObjectName(QLatin1String("qt_edit_menu"));
2228  QAction *action = 0;
2229 
2230  if (!isReadOnly()) {
2231  action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo));
2232  action->setEnabled(d->control->isUndoAvailable());
2233  connect(action, SIGNAL(triggered()), SLOT(undo()));
2234 
2235  action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo));
2236  action->setEnabled(d->control->isRedoAvailable());
2237  connect(action, SIGNAL(triggered()), SLOT(redo()));
2238 
2239  popup->addSeparator();
2240  }
2241 
2242 #ifndef QT_NO_CLIPBOARD
2243  if (!isReadOnly()) {
2244  action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut));
2245  action->setEnabled(!d->control->isReadOnly() && d->control->hasSelectedText()
2246  && d->control->echoMode() == QLineEdit::Normal);
2247  connect(action, SIGNAL(triggered()), SLOT(cut()));
2248  }
2249 
2250  action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy));
2251  action->setEnabled(d->control->hasSelectedText()
2252  && d->control->echoMode() == QLineEdit::Normal);
2253  connect(action, SIGNAL(triggered()), SLOT(copy()));
2254 
2255  if (!isReadOnly()) {
2256  action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste));
2257  action->setEnabled(!d->control->isReadOnly() && !QApplication::clipboard()->text().isEmpty());
2258  connect(action, SIGNAL(triggered()), SLOT(paste()));
2259  }
2260 #endif
2261 
2262  if (!isReadOnly()) {
2263  action = popup->addAction(QLineEdit::tr("Delete"));
2264  action->setEnabled(!d->control->isReadOnly() && !d->control->text().isEmpty() && d->control->hasSelectedText());
2265  connect(action, SIGNAL(triggered()), d->control, SLOT(_q_deleteSelected()));
2266  }
2267 
2268  if (!popup->isEmpty())
2269  popup->addSeparator();
2270 
2271  action = popup->addAction(QLineEdit::tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll));
2272  action->setEnabled(!d->control->text().isEmpty() && !d->control->allSelected());
2273  d->selectAllAction = action;
2274  connect(action, SIGNAL(triggered()), SLOT(selectAll()));
2275 
2276 #if !defined(QT_NO_IM)
2277  QInputContext *qic = inputContext();
2278  if (qic) {
2279  QList<QAction *> imActions = qic->actions();
2280  for (int i = 0; i < imActions.size(); ++i)
2281  popup->addAction(imActions.at(i));
2282  }
2283 #endif
2284 
2285 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
2286  if (!d->control->isReadOnly() && qt_use_rtl_extensions) {
2287 #else
2288  if (!d->control->isReadOnly()) {
2289 #endif
2290  popup->addSeparator();
2291  QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, popup);
2292  popup->addMenu(ctrlCharacterMenu);
2293  }
2294  return popup;
2295 }
double d
Definition: qnumeric_p.h:62
void undo()
Undoes the last operation if undo is available.
Definition: qlineedit.cpp:1456
void copy() const
Copies the selected text to the clipboard, if there is any, and if echoMode() is Normal ...
Definition: qlineedit.cpp:1541
void cut()
Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode() is Norma...
Definition: qlineedit.cpp:1525
#define SLOT(a)
Definition: qobjectdefs.h:226
#define ACCEL_KEY(k)
Definition: qlineedit.cpp:82
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
#define Q_D(Class)
Definition: qglobal.h:2482
virtual QList< QAction * > actions()
This is a preliminary interface for Qt 4.
void setEnabled(bool)
Definition: qaction.cpp:1192
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define SIGNAL(a)
Definition: qobjectdefs.h:227
bool isEmpty() const
Returns true if there are no visible actions inserted into the menu, false otherwise.
Definition: qmenu.cpp:1737
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition: qmenu.cpp:1583
void paste()
Inserts the clipboard&#39;s text at the cursor position, deleting any selected text, providing the line e...
Definition: qlineedit.cpp:1558
QInputContext * inputContext()
This function returns the QInputContext for this widget.
Definition: qwidget.cpp:474
bool isReadOnly() const
Definition: qlineedit.cpp:1493
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
bool qt_use_rtl_extensions
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QAction * addMenu(QMenu *menu)
This convenience function adds menu as a submenu to this menu.
Definition: qmenu.cpp:1541
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void redo()
Redoes the last operation if redo is available.
Definition: qlineedit.cpp:1467
void selectAll()
Selects all the text (i.e.
Definition: qlineedit.cpp:1405
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
QString text(Mode mode=Clipboard) const
Returns the clipboard text as plain text, or an empty string if the clipboard does not contain any te...
Definition: qclipboard.cpp:357
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ cursorBackward()

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()

Definition at line 857 of file qlineedit.cpp.

858 {
859  cursorForward(mark, -steps);
860 }
void cursorForward(bool mark, int steps=1)
Moves the cursor forward steps characters.
Definition: qlineedit.cpp:843

◆ 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()

Definition at line 843 of file qlineedit.cpp.

Referenced by cursorBackward().

844 {
845  Q_D(QLineEdit);
846  d->control->cursorForward(mark, steps);
847 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ cursorMoveStyle()

Qt::CursorMoveStyle QLineEdit::cursorMoveStyle ( ) const

Referenced by setDragEnabled().

◆ cursorPosition()

int QLineEdit::cursorPosition ( ) const

Referenced by minimumSizeHint().

◆ cursorPositionAt()

int QLineEdit::cursorPositionAt ( const QPoint pos)

Returns the cursor position under the point pos.

Definition at line 768 of file qlineedit.cpp.

Referenced by QAccessibleLineEdit::offsetAtPoint().

769 {
770  Q_D(QLineEdit);
771  return d->xToPos(pos.x());
772 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ cursorPositionChanged

void QLineEdit::cursorPositionChanged ( int  old,
int  new 
)
signal

This signal is emitted whenever the cursor moves.

The previous position is given by old, and the new position by new.

See also
setCursorPosition(), cursorPosition()

◆ cursorRect()

QRect QLineEdit::cursorRect ( ) const
protected

Returns a rectangle that includes the lineedit cursor.

Since
4.4

Definition at line 1825 of file qlineedit.cpp.

1826 {
1827  Q_D(const QLineEdit);
1828  return d->cursorRect();
1829 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ cursorWordBackward()

void QLineEdit::cursorWordBackward ( bool  mark)

Moves the cursor one word backward.

If mark is true, the word is also selected.

See also
cursorWordForward()

Definition at line 881 of file qlineedit.cpp.

882 {
883  Q_D(QLineEdit);
884  d->control->cursorWordBackward(mark);
885 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ cursorWordForward()

void QLineEdit::cursorWordForward ( bool  mark)

Moves the cursor one word forward.

If mark is true, the word is also selected.

See also
cursorWordBackward()

Definition at line 868 of file qlineedit.cpp.

869 {
870  Q_D(QLineEdit);
871  d->control->cursorWordForward(mark);
872 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ cut

void QLineEdit::cut ( )
slot

Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode() is Normal .

If the current validator disallows deleting the selected text, cut() will copy without deleting.

See also
copy() paste() setValidator()

Definition at line 1525 of file qlineedit.cpp.

Referenced by createStandardContextMenu().

1526 {
1527  if (hasSelectedText()) {
1528  copy();
1529  del();
1530  }
1531 }
bool hasSelectedText() const
void copy() const
Copies the selected text to the clipboard, if there is any, and if echoMode() is Normal ...
Definition: qlineedit.cpp:1541
void del()
If no text is selected, deletes the character to the right of the text cursor.
Definition: qlineedit.cpp:910

◆ del()

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()

Definition at line 910 of file qlineedit.cpp.

Referenced by cut().

911 {
912  Q_D(QLineEdit);
913  d->control->del();
914 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ deselect()

void QLineEdit::deselect ( )

Deselects any selected text.

See also
setSelection() selectAll()

Definition at line 1417 of file qlineedit.cpp.

Referenced by QComboBoxPrivate::_q_returnPressed(), dropEvent(), focusOutEvent(), mouseReleaseEvent(), and QAccessibleLineEdit::removeSelection().

1418 {
1419  Q_D(QLineEdit);
1420  d->control->deselect();
1421 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ displayText()

QString QLineEdit::displayText ( ) const

◆ dragEnabled()

bool QLineEdit::dragEnabled ( ) const

Referenced by isRedoAvailable().

◆ dragEnterEvent()

void QLineEdit::dragEnterEvent ( QDragEnterEvent e)
protectedvirtual

em>Reimplemented Function

Reimplemented from QWidget.

Definition at line 2135 of file qlineedit.cpp.

◆ dragLeaveEvent()

void QLineEdit::dragLeaveEvent ( QDragLeaveEvent e)
protectedvirtual

em>Reimplemented Function

Reimplemented from QWidget.

Definition at line 2141 of file qlineedit.cpp.

◆ dragMoveEvent()

void QLineEdit::dragMoveEvent ( QDragMoveEvent e)
protectedvirtual

em>Reimplemented Function

Reimplemented from QWidget.

Definition at line 2123 of file qlineedit.cpp.

Referenced by dragEnterEvent().

◆ dropEvent()

void QLineEdit::dropEvent ( QDropEvent event)
protectedvirtual

This event handler is called when the drag is dropped on this widget.

The event is passed in the event parameter.

See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.

See also
QDrag, QDropEvent

Reimplemented from QWidget.

Definition at line 2151 of file qlineedit.cpp.

2152 {
2153  Q_D(QLineEdit);
2154  QString str = e->mimeData()->text();
2155 
2156  if (!str.isNull() && !d->control->isReadOnly()) {
2157  if (e->source() == this && e->dropAction() == Qt::CopyAction)
2158  deselect();
2159  int cursorPos = d->xToPos(e->pos().x());
2160  int selStart = cursorPos;
2161  int oldSelStart = d->control->selectionStart();
2162  int oldSelEnd = d->control->selectionEnd();
2163  d->control->moveCursor(cursorPos, false);
2164  d->cursorVisible = false;
2165  e->acceptProposedAction();
2166  insert(str);
2167  if (e->source() == this) {
2168  if (e->dropAction() == Qt::MoveAction) {
2169  if (selStart > oldSelStart && selStart <= oldSelEnd)
2170  setSelection(oldSelStart, str.length());
2171  else if (selStart > oldSelEnd)
2172  setSelection(selStart - str.length(), str.length());
2173  else
2174  setSelection(selStart, str.length());
2175  } else {
2176  setSelection(selStart, str.length());
2177  }
2178  }
2179  } else {
2180  e->ignore();
2181  update();
2182  }
2183 }
double d
Definition: qnumeric_p.h:62
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void deselect()
Deselects any selected text.
Definition: qlineedit.cpp:1417
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void insert(const QString &)
Deletes any selected text, inserts newText, and validates the result.
Definition: qlineedit.cpp:1431
void setSelection(int, int)
Selects text from position start and for length characters.
Definition: qlineedit.cpp:1106
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ echoMode()

EchoMode QLineEdit::echoMode ( ) const

Referenced by inputMethodEvent(), and setFrame().

◆ editingFinished

void QLineEdit::editingFinished ( )
signal

This signal is emitted when the Return or Enter key is pressed or the line edit loses focus.

Note that 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 follows the inputMask() and the validator() returns QValidator::Acceptable.

Referenced by event(), and focusOutEvent().

◆ end()

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()

Definition at line 940 of file qlineedit.cpp.

Referenced by QComboBoxPrivate::_q_returnPressed(), event(), and selectionStart().

941 {
942  Q_D(QLineEdit);
943  d->control->end(mark);
944 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ event()

bool QLineEdit::event ( QEvent e)
virtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1568 of file qlineedit.cpp.

1569 {
1570  Q_D(QLineEdit);
1571  if (e->type() == QEvent::Timer) {
1572  // should be timerEvent, is here for binary compatibility
1573  int timerId = ((QTimerEvent*)e)->timerId();
1574  if (false) {
1575 #ifndef QT_NO_DRAGANDDROP
1576  } else if (timerId == d->dndTimer.timerId()) {
1577  d->drag();
1578 #endif
1579  }
1580  else if (timerId == d->tripleClickTimer.timerId())
1581  d->tripleClickTimer.stop();
1582  } else if (e->type() == QEvent::ContextMenu) {
1583 #ifndef QT_NO_IM
1584  if (d->control->composeMode())
1585  return true;
1586 #endif
1587  //d->separate();
1588  } else if (e->type() == QEvent::WindowActivate) {
1589  QTimer::singleShot(0, this, SLOT(_q_handleWindowActivate()));
1590  }else if(e->type() == QEvent::ShortcutOverride){
1591  d->control->processEvent(e);
1592  } else if (e->type() == QEvent::KeyRelease) {
1593  d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime());
1594  } else if (e->type() == QEvent::Show) {
1595  //In order to get the cursor blinking if QComboBox::setEditable is called when the combobox has focus
1596  if (hasFocus()) {
1597  d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime());
1598  QStyleOptionFrameV2 opt;
1599  initStyleOption(&opt);
1600  if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty())
1602  d->setCursorVisible(true);
1603  }
1604  }
1605 
1606 #ifdef QT_KEYPAD_NAVIGATION
1607  if (QApplication::keypadNavigationEnabled()) {
1608  if (e->type() == QEvent::EnterEditFocus) {
1609  end(false);
1610  d->setCursorVisible(true);
1611  d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime());
1612  } else if (e->type() == QEvent::LeaveEditFocus) {
1613  d->setCursorVisible(false);
1614  d->control->setCursorBlinkPeriod(0);
1615  if (d->control->hasAcceptableInput() || d->control->fixup())
1617  }
1618  }
1619 #endif
1620  return QWidget::event(e);
1621 }
double d
Definition: qnumeric_p.h:62
bool hasSelectedText() const
#define SLOT(a)
Definition: qobjectdefs.h:226
void end(bool mark)
Moves the text cursor to the end of the line unless it is already there.
Definition: qlineedit.cpp:940
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
static int cursorFlashTime()
bool hasFocus() const
Definition: qwidget.cpp:6583
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
#define emit
Definition: qobjectdefs.h:76
void editingFinished()
This signal is emitted when the Return or Enter key is pressed or the line edit loses focus...
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
void initStyleOption(QStyleOptionFrame *option) const
Initialize option with the values from this QLineEdit.
Definition: qlineedit.cpp:104
The QStyleOptionFrameV2 class is used to describe the parameters necessary for drawing a frame in Qt ...
Definition: qstyleoption.h:134
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ focusInEvent()

void QLineEdit::focusInEvent ( QFocusEvent e)
protectedvirtual

em>Reimplemented Function

Reimplemented from QWidget.

Definition at line 1900 of file qlineedit.cpp.

◆ focusOutEvent()

void QLineEdit::focusOutEvent ( QFocusEvent e)
protectedvirtual

em>Reimplemented Function

Reimplemented from QWidget.

Definition at line 1949 of file qlineedit.cpp.

◆ getTextMargins()

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

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

Since
4.5
See also
setTextMargins()

Definition at line 1290 of file qlineedit.cpp.

Referenced by QAccessibleLineEdit::characterRect(), and QExpandingLineEdit::updateMinimumWidth().

1291 {
1292  Q_D(const QLineEdit);
1293  if (left)
1294  *left = d->leftTextMargin;
1295  if (top)
1296  *top = d->topTextMargin;
1297  if (right)
1298  *right = d->rightTextMargin;
1299  if (bottom)
1300  *bottom = d->bottomTextMargin;
1301 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ hasAcceptableInput()

bool QLineEdit::hasAcceptableInput ( ) const

Definition at line 1246 of file qlineedit.cpp.

Referenced by cursorPositionAt(), focusOutEvent(), and QScriptNewBreakpointWidget::onTextChanged().

1247 {
1248  Q_D(const QLineEdit);
1249  return d->control->hasAcceptableInput();
1250 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ hasFrame()

bool QLineEdit::hasFrame ( ) const

Definition at line 507 of file qlineedit.cpp.

508 {
509  Q_D(const QLineEdit);
510  return d->frame;
511 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ hasSelectedText()

bool QLineEdit::hasSelectedText ( ) const

Referenced by cut(), event(), focusInEvent(), and setModified().

◆ home()

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()

Definition at line 925 of file qlineedit.cpp.

926 {
927  Q_D(QLineEdit);
928  d->control->home(mark);
929 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ initStyleOption()

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 or QStyleOptionFrameV2, but don't want to fill in all the information themselves. This function will check the version of the QStyleOptionFrame and fill in the additional values for a QStyleOptionFrameV2.

See also
QStyleOption::initFrom()

Definition at line 104 of file qlineedit.cpp.

Referenced by changeEvent(), event(), focusInEvent(), minimumSizeHint(), paintEvent(), setSelection(), sizeHint(), and QExpandingLineEdit::updateMinimumWidth().

105 {
106  if (!option)
107  return;
108 
109  Q_D(const QLineEdit);
110  option->initFrom(this);
111  option->rect = contentsRect();
112  option->lineWidth = d->frame ? style()->pixelMetric(QStyle::PM_DefaultFrameWidth, option, this)
113  : 0;
114  option->midLineWidth = 0;
115  option->state |= QStyle::State_Sunken;
116  if (d->control->isReadOnly())
117  option->state |= QStyle::State_ReadOnly;
118 #ifdef QT_KEYPAD_NAVIGATION
119  if (hasEditFocus())
120  option->state |= QStyle::State_HasEditFocus;
121 #endif
122  if (QStyleOptionFrameV2 *optionV2 = qstyleoption_cast<QStyleOptionFrameV2 *>(option))
123  optionV2->features = QStyleOptionFrameV2::None;
124 }
double d
Definition: qnumeric_p.h:62
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
QRect contentsRect() const
Returns the area inside the widget&#39;s margins.
Definition: qwidget.cpp:7544
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
int lineWidth
the line width for drawing the frame
Definition: qstyleoption.h:124
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
int midLineWidth
the mid-line width for drawing the frame
Definition: qstyleoption.h:125
if(void) toggleToolbarShown
The QStyleOptionFrameV2 class is used to describe the parameters necessary for drawing a frame in Qt ...
Definition: qstyleoption.h:134
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90

◆ inputMask()

QString QLineEdit::inputMask ( ) const

Referenced by QLineEdit(), and textMargins().

◆ inputMethodEvent()

void QLineEdit::inputMethodEvent ( QInputMethodEvent e)
protectedvirtual

Reimplemented Function

em>Reimplemented Function

Reimplemented from QWidget.

Definition at line 1833 of file qlineedit.cpp.

◆ inputMethodQuery()

QVariant QLineEdit::inputMethodQuery ( Qt::InputMethodQuery  property) const
virtual

em>Reimplemented Function

Reimplemented from QWidget.

Definition at line 1869 of file qlineedit.cpp.

◆ insert()

void QLineEdit::insert ( const QString newText)

Deletes any selected text, inserts newText, and validates the result.

If it is valid, it sets it as the new contents of the line edit.

See also
setText(), clear()

Definition at line 1431 of file qlineedit.cpp.

Referenced by dropEvent(), and mouseReleaseEvent().

1432 {
1433 // q->resetInputContext(); //#### FIX ME IN QT
1434  Q_D(QLineEdit);
1435  d->control->insert(newText);
1436 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ isModified()

bool QLineEdit::isModified ( ) const

Definition at line 968 of file qlineedit.cpp.

Referenced by QPrintDialogPrivate::_q_okClicked(), QPrintDialogPrivate::_q_printerOrFileSelected(), and selectionStart().

969 {
970  Q_D(const QLineEdit);
971  return d->control->isModified();
972 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ isReadOnly()

bool QLineEdit::isReadOnly ( ) const

Definition at line 1493 of file qlineedit.cpp.

Referenced by createStandardContextMenu(), keyPressEvent(), mouseReleaseEvent(), and QAccessibleLineEdit::state().

1494 {
1495  Q_D(const QLineEdit);
1496  return d->control->isReadOnly();
1497 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ isRedoAvailable()

bool QLineEdit::isRedoAvailable ( ) const

Definition at line 1156 of file qlineedit.cpp.

1157 {
1158  Q_D(const QLineEdit);
1159  return d->control->isRedoAvailable();
1160 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ isUndoAvailable()

bool QLineEdit::isUndoAvailable ( ) const

Definition at line 1137 of file qlineedit.cpp.

1138 {
1139  Q_D(const QLineEdit);
1140  return d->control->isUndoAvailable();
1141 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ keyPressEvent()

void QLineEdit::keyPressEvent ( QKeyEvent event)
protectedvirtual

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's detailed description.

Reimplemented from QWidget.

Definition at line 1764 of file qlineedit.cpp.

Referenced by QFileDialogLineEdit::keyPressEvent().

1765 {
1766  Q_D(QLineEdit);
1767  #ifdef QT_KEYPAD_NAVIGATION
1768  bool select = false;
1769  switch (event->key()) {
1770  case Qt::Key_Select:
1771  if (QApplication::keypadNavigationEnabled()) {
1772  if (hasEditFocus()) {
1773  setEditFocus(false);
1774  if (d->control->completer() && d->control->completer()->popup()->isVisible())
1775  d->control->completer()->popup()->hide();
1776  select = true;
1777  }
1778  }
1779  break;
1780  case Qt::Key_Back:
1781  case Qt::Key_No:
1782  if (!QApplication::keypadNavigationEnabled() || !hasEditFocus()) {
1783  event->ignore();
1784  return;
1785  }
1786  break;
1787  default:
1788  if (QApplication::keypadNavigationEnabled()) {
1789  if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) {
1790  if (!event->text().isEmpty() && event->text().at(0).isPrint()
1791  && !isReadOnly())
1792  setEditFocus(true);
1793  else {
1794  event->ignore();
1795  return;
1796  }
1797  }
1798  }
1799  }
1800 
1801 
1802 
1803  if (QApplication::keypadNavigationEnabled() && !select && !hasEditFocus()) {
1804  setEditFocus(true);
1805  if (event->key() == Qt::Key_Select)
1806  return; // Just start. No action.
1807  }
1808 #endif
1809  d->control->processKeyEvent(event);
1810  if (event->isAccepted()) {
1811  if (layoutDirection() != d->control->layoutDirection())
1812  setLayoutDirection(d->control->layoutDirection());
1813  d->control->setCursorBlinkPeriod(0);
1814  }
1815 }
double d
Definition: qnumeric_p.h:62
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
#define Q_D(Class)
Definition: qglobal.h:2482
void setLayoutDirection(Qt::LayoutDirection direction)
Definition: qwidget.cpp:5199
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
bool isAccepted() const
Definition: qcoreevent.h:307
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool isReadOnly() const
Definition: qlineedit.cpp:1493
Qt::LayoutDirection layoutDirection() const
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ maxLength()

int QLineEdit::maxLength ( ) const

◆ minimumSizeHint()

QSize QLineEdit::minimumSizeHint ( ) const
virtual

Returns a minimum size for the line edit.

The width returned is enough for at least one character.

Reimplemented from QWidget.

Definition at line 725 of file qlineedit.cpp.

726 {
727  Q_D(const QLineEdit);
728  ensurePolished();
729  QFontMetrics fm = fontMetrics();
730  int h = fm.height() + qMax(2*d->verticalMargin, fm.leading())
731  + d->topmargin + d->bottommargin;
732  int w = fm.maxWidth() + d->leftmargin + d->rightmargin;
734  initStyleOption(&opt);
735  return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h).
736  expandedTo(QApplication::globalStrut()), this));
737 }
double d
Definition: qnumeric_p.h:62
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
int leading() const
Returns the leading of the font.
int maxWidth() const
Returns the width of the widest character in the font.
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
static QSize globalStrut()
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
void initStyleOption(QStyleOptionFrame *option) const
Initialize option with the values from this QLineEdit.
Definition: qlineedit.cpp:104
The QStyleOptionFrameV2 class is used to describe the parameters necessary for drawing a frame in Qt ...
Definition: qstyleoption.h:134
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
int height() const
Returns the height of the font.

◆ mouseDoubleClickEvent()

void QLineEdit::mouseDoubleClickEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1715 of file qlineedit.cpp.

1716 {
1717  Q_D(QLineEdit);
1718  if (d->sendMouseEventToInputContext(e))
1719  return;
1720  if (e->button() == Qt::LeftButton) {
1721  d->control->selectWordAtPos(d->xToPos(e->pos().x()));
1722  d->tripleClickTimer.start(QApplication::doubleClickInterval(), this);
1723  d->tripleClick = e->pos();
1724  }
1725 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
static int doubleClickInterval()

◆ mouseMoveEvent()

void QLineEdit::mouseMoveEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1662 of file qlineedit.cpp.

1663 {
1664  Q_D(QLineEdit);
1665  if (d->sendMouseEventToInputContext(e))
1666  return;
1667 
1668  if (e->buttons() & Qt::LeftButton) {
1669 #ifndef QT_NO_DRAGANDDROP
1670  if (d->dndTimer.isActive()) {
1671  if ((d->dndPos - e->pos()).manhattanLength() > QApplication::startDragDistance())
1672  d->drag();
1673  } else
1674 #endif
1675  {
1676  d->control->moveCursor(d->xToPos(e->pos().x()), true);
1677  }
1678  }
1679 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
static int startDragDistance()
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ mousePressEvent()

void QLineEdit::mousePressEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1625 of file qlineedit.cpp.

1626 {
1627  Q_D(QLineEdit);
1628  if (d->sendMouseEventToInputContext(e))
1629  return;
1630  if (e->button() == Qt::RightButton)
1631  return;
1632 #ifdef QT_KEYPAD_NAVIGATION
1633  if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
1634  setEditFocus(true);
1635  // Get the completion list to pop up.
1636  if (d->control->completer())
1637  d->control->completer()->complete();
1638  }
1639 #endif
1640  if (d->tripleClickTimer.isActive() && (e->pos() - d->tripleClick).manhattanLength() <
1642  selectAll();
1643  return;
1644  }
1645  bool mark = e->modifiers() & Qt::ShiftModifier;
1646  int cursor = d->xToPos(e->pos().x());
1647 #ifndef QT_NO_DRAGANDDROP
1648  if (!mark && d->dragEnabled && d->control->echoMode() == Normal &&
1649  e->button() == Qt::LeftButton && d->control->inSelection(e->pos().x())) {
1650  d->dndPos = e->pos();
1651  if (!d->dndTimer.isActive())
1652  d->dndTimer.start(QApplication::startDragTime(), this);
1653  } else
1654 #endif
1655  {
1656  d->control->moveCursor(cursor, mark);
1657  }
1658 }
double d
Definition: qnumeric_p.h:62
QCursor cursor() const
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
static int startDragTime()
static int startDragDistance()
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void selectAll()
Selects all the text (i.e.
Definition: qlineedit.cpp:1405
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79

◆ mouseReleaseEvent()

void QLineEdit::mouseReleaseEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1683 of file qlineedit.cpp.

1684 {
1685  Q_D(QLineEdit);
1686  if (d->sendMouseEventToInputContext(e))
1687  return;
1688 #ifndef QT_NO_DRAGANDDROP
1689  if (e->button() == Qt::LeftButton) {
1690  if (d->dndTimer.isActive()) {
1691  d->dndTimer.stop();
1692  deselect();
1693  return;
1694  }
1695  }
1696 #endif
1697 #ifndef QT_NO_CLIPBOARD
1698  if (QApplication::clipboard()->supportsSelection()) {
1699  if (e->button() == Qt::LeftButton) {
1700  d->control->copy(QClipboard::Selection);
1701  } else if (!d->control->isReadOnly() && e->button() == Qt::MidButton) {
1702  deselect();
1704  }
1705  }
1706 #endif
1707 
1708  if (!isReadOnly() && rect().contains(e->pos()))
1709  d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
1710  d->clickCausedFocus = 0;
1711 }
double d
Definition: qnumeric_p.h:62
void deselect()
Deselects any selected text.
Definition: qlineedit.cpp:1417
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
void insert(const QString &)
Deletes any selected text, inserts newText, and validates the result.
Definition: qlineedit.cpp:1431
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
QRect rect() const
bool isReadOnly() const
Definition: qlineedit.cpp:1493
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
QString text() const

◆ paintEvent()

void QLineEdit::paintEvent ( QPaintEvent )
protectedvirtual

em>Reimplemented Function

Reimplemented from QWidget.

Definition at line 1994 of file qlineedit.cpp.

◆ paste

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, nothing happens.

See also
copy() cut()

Definition at line 1558 of file qlineedit.cpp.

Referenced by createStandardContextMenu().

1559 {
1560  Q_D(QLineEdit);
1561  d->control->paste();
1562 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ placeholderText()

QString QLineEdit::placeholderText ( ) const

Referenced by setPlaceholderText(), and setText().

◆ redo

void QLineEdit::redo ( )
slot

Redoes the last operation if redo is available.

Definition at line 1467 of file qlineedit.cpp.

Referenced by createStandardContextMenu().

1468 {
1469  Q_D(QLineEdit);
1471  d->control->redo();
1472 }
double d
Definition: qnumeric_p.h:62
void resetInputContext()
This function can be called on the widget that currently has focus to reset the input method operatin...
Definition: qwidget.cpp:522
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ returnPressed

void QLineEdit::returnPressed ( )
signal

This signal is emitted when the Return or Enter key is pressed.

Note that if there is a validator() or inputMask() set on the line edit, the returnPressed() signal will only be emitted if the input follows the inputMask() and the validator() returns QValidator::Acceptable.

◆ selectAll

void QLineEdit::selectAll ( )
slot

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.

See also
setSelection() deselect()

Definition at line 1405 of file qlineedit.cpp.

Referenced by QComboBoxPrivate::_q_itemSelected(), QPrintDialogPrivate::_q_printerOrFileSelected(), createStandardContextMenu(), focusInEvent(), mousePressEvent(), and QDateTimeEditPrivate::setSelected().

1406 {
1407  Q_D(QLineEdit);
1408  d->control->selectAll();
1409 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ selectedText()

QString QLineEdit::selectedText ( ) const

◆ selectionChanged

void QLineEdit::selectionChanged ( )
signal

This signal is emitted whenever the selection changes.

See also
hasSelectedText(), selectedText()

◆ selectionStart()

int QLineEdit::selectionStart ( ) const

selectionStart() returns the index of the first selected character in the line edit or -1 if no text is selected.

See also
selectedText()

Definition at line 1039 of file qlineedit.cpp.

Referenced by QDateTimeEditPrivate::_q_editorCursorPositionChanged(), QAbstractSpinBoxPrivate::_q_editorCursorPositionChanged(), and QAccessibleLineEdit::selection().

1040 {
1041  Q_D(const QLineEdit);
1042  return d->control->selectionStart();
1043 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ setAlignment()

void QLineEdit::setAlignment ( Qt::Alignment  flag)

Definition at line 827 of file qlineedit.cpp.

828 {
829  Q_D(QLineEdit);
830  d->alignment = alignment;
831  update();
832 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
Qt::Alignment alignment() const

◆ setCompleter()

void QLineEdit::setCompleter ( QCompleter c)

Sets this line edit to provide auto completions from the completer, c.

Since
4.2

The completion mode is set using QCompleter::setCompletionMode().

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.

If c == 0, setCompleter() removes the current completer, effectively disabling auto completion.

See also
QCompleter

Definition at line 654 of file qlineedit.cpp.

Referenced by QScriptNewBreakpointWidget::setCompleter().

655 {
656  Q_D(QLineEdit);
657  if (c == d->control->completer())
658  return;
659  if (d->control->completer()) {
660  disconnect(d->control->completer(), 0, this, 0);
661  d->control->completer()->setWidget(0);
662  if (d->control->completer()->parent() == this)
663  delete d->control->completer();
664  }
665  d->control->setCompleter(c);
666  if (!c)
667  return;
668  if (c->widget() == 0)
669  c->setWidget(this);
670  if (hasFocus()) {
671  QObject::connect(d->control->completer(), SIGNAL(activated(QString)),
672  this, SLOT(setText(QString)));
673  QObject::connect(d->control->completer(), SIGNAL(highlighted(QString)),
674  this, SLOT(_q_completionHighlighted(QString)));
675  }
676 }
double d
Definition: qnumeric_p.h:62
#define SLOT(a)
Definition: qobjectdefs.h:226
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool hasFocus() const
Definition: qwidget.cpp:6583
#define Q_D(Class)
Definition: qglobal.h:2482
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void setText(const QString &)
Definition: qlineedit.cpp:401
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void setWidget(QWidget *widget)
Sets the widget for which completion are provided for to widget.
Definition: qcompleter.cpp:989
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
QWidget * widget() const
Returns the widget for which the completer object is providing completions.

◆ setCursorMoveStyle()

void QLineEdit::setCursorMoveStyle ( Qt::CursorMoveStyle  style)

Sets the movement style for the cursor in the line edit to the given style.

Since
4.8

Definition at line 1228 of file qlineedit.cpp.

1229 {
1230  Q_D(QLineEdit);
1231  d->control->setCursorMoveStyle(style);
1232 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ setCursorPosition()

void QLineEdit::setCursorPosition ( int  pos)

◆ setDragEnabled()

void QLineEdit::setDragEnabled ( bool  b)

Definition at line 1179 of file qlineedit.cpp.

1180 {
1181  Q_D(QLineEdit);
1182  d->dragEnabled = b;
1183 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ setEchoMode()

void QLineEdit::setEchoMode ( EchoMode  mode)

Definition at line 575 of file qlineedit.cpp.

576 {
577  Q_D(QLineEdit);
578  if (mode == (EchoMode)d->control->echoMode())
579  return;
580  Qt::InputMethodHints imHints = inputMethodHints();
581  if (mode == Password || mode == NoEcho) {
582  imHints |= Qt::ImhHiddenText;
583  } else {
584  imHints &= ~Qt::ImhHiddenText;
585  }
586  if (mode != Normal) {
588  } else {
590  }
591  setInputMethodHints(imHints);
592  d->control->setEchoMode(mode);
593  update();
594 #ifdef Q_WS_MAC
595  if (hasFocus())
596  qt_mac_secure_keyboard(mode == Password || mode == NoEcho);
597 #endif
598 }
double d
Definition: qnumeric_p.h:62
void setInputMethodHints(Qt::InputMethodHints hints)
Definition: qwidget.cpp:9736
void qt_mac_secure_keyboard(bool)
bool hasFocus() const
Definition: qwidget.cpp:6583
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
EchoMode
This enum type describes how a line edit should display its contents.
Definition: qlineedit.h:113
Definition: qnamespace.h:54
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
Qt::InputMethodHints inputMethodHints() const

◆ setFrame()

void QLineEdit::setFrame ( bool  enable)

Definition at line 514 of file qlineedit.cpp.

Referenced by QDefaultItemEditorFactory::createEditor().

515 {
516  Q_D(QLineEdit);
517  d->frame = enable;
518  update();
519  updateGeometry();
520 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372

◆ setInputMask()

void QLineEdit::setInputMask ( const QString inputMask)

Definition at line 1390 of file qlineedit.cpp.

1391 {
1392  Q_D(QLineEdit);
1393  d->control->setInputMask(inputMask);
1394 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ setMaxLength()

void QLineEdit::setMaxLength ( int  maxLength)

Definition at line 491 of file qlineedit.cpp.

492 {
493  Q_D(QLineEdit);
494  d->control->setMaxLength(maxLength);
495 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int maxLength() const
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ setModified()

void QLineEdit::setModified ( bool  modified)

Definition at line 974 of file qlineedit.cpp.

Referenced by QPrintDialogPrivate::_q_printerOrFileSelected(), selectionStart(), and QPrintDialogPrivate::setPrinter().

975 {
976  Q_D(QLineEdit);
977  d->control->setModified(modified);
978 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool modified
whether the line edit&#39;s contents has been modified by the user
Definition: qlineedit.h:79
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ setPlaceholderText()

void QLineEdit::setPlaceholderText ( const QString placeholderText)

Definition at line 430 of file qlineedit.cpp.

431 {
432  Q_D(QLineEdit);
433  if (d->placeholderText != placeholderText) {
434  d->placeholderText = placeholderText;
435  if (!hasFocus())
436  update();
437  }
438 }
double d
Definition: qnumeric_p.h:62
bool hasFocus() const
Definition: qwidget.cpp:6583
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
QString placeholderText() const

◆ setReadOnly()

void QLineEdit::setReadOnly ( bool  enable)

Definition at line 1499 of file qlineedit.cpp.

1500 {
1501  Q_D(QLineEdit);
1502  if (d->control->isReadOnly() != enable) {
1503  d->control->setReadOnly(enable);
1505  setAttribute(Qt::WA_InputMethodEnabled, d->shouldEnableInputMethod());
1506 #ifndef QT_NO_CURSOR
1508 #endif
1509  update();
1510  }
1511 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087

◆ setSelection()

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()

Definition at line 1106 of file qlineedit.cpp.

Referenced by QAbstractSpinBoxPrivate::_q_editorCursorPositionChanged(), cursorPositionAt(), dropEvent(), QDateTimeEditPrivate::setSelected(), QAccessibleLineEdit::setSelection(), QDateTimeEditPrivate::updateEdit(), and QAbstractSpinBoxPrivate::updateEdit().

1107 {
1108  Q_D(QLineEdit);
1109  if (start < 0 || start > (int)d->control->text().length()) {
1110  qWarning("QLineEdit::setSelection: Invalid start position (%d)", start);
1111  return;
1112  }
1113 
1114  d->control->setSelection(start, length);
1115 
1116  if (d->control->hasSelectedText()){
1117  QStyleOptionFrameV2 opt;
1118  initStyleOption(&opt);
1120  d->setCursorVisible(false);
1121  }
1122 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
const char * styleHint(const QFontDef &request)
Q_CORE_EXPORT void qWarning(const char *,...)
void initStyleOption(QStyleOptionFrame *option) const
Initialize option with the values from this QLineEdit.
Definition: qlineedit.cpp:104
The QStyleOptionFrameV2 class is used to describe the parameters necessary for drawing a frame in Qt ...
Definition: qstyleoption.h:134
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ setText

void QLineEdit::setText ( const QString text)
slot

◆ setTextMargins() [1/2]

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.

Since
4.5

See also getTextMargins().

Definition at line 1259 of file qlineedit.cpp.

Referenced by setTextMargins().

1260 {
1261  Q_D(QLineEdit);
1262  d->leftTextMargin = left;
1263  d->topTextMargin = top;
1264  d->rightTextMargin = right;
1265  d->bottomTextMargin = bottom;
1266  updateGeometry();
1267  update();
1268 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ setTextMargins() [2/2]

void QLineEdit::setTextMargins ( const QMargins margins)

Sets the margins around the text inside the frame.

Since
4.6

See also textMargins().

Definition at line 1279 of file qlineedit.cpp.

1280 {
1281  setTextMargins(margins.left(), margins.top(), margins.right(), margins.bottom());
1282 }
void 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.
Definition: qlineedit.cpp:1259
int top() const
Returns the top margin.
Definition: qmargins.h:99
int left() const
Returns the left margin.
Definition: qmargins.h:96
int bottom() const
Returns the bottom margin.
Definition: qmargins.h:105
int right() const
Returns the right margin.
Definition: qmargins.h:102

◆ setValidator()

void QLineEdit::setValidator ( const QValidator v)

Sets this line edit to only accept input that the validator, v, will accept.

This allows you to place any arbitrary constraints on the text which may be entered.

If 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()).

See also
validator() QIntValidator QDoubleValidator QRegExpValidator

Definition at line 627 of file qlineedit.cpp.

Referenced by QAbstractSpinBoxPrivate::init(), and QScriptNewBreakpointWidget::QScriptNewBreakpointWidget().

628 {
629  Q_D(QLineEdit);
630  d->control->setValidator(v);
631 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ sizeHint()

QSize QLineEdit::sizeHint ( ) const
virtual

Returns a recommended size for the widget.

The width returned, in pixels, is usually enough for about 15 to 20 characters.

Reimplemented from QWidget.

Definition at line 701 of file qlineedit.cpp.

702 {
703  Q_D(const QLineEdit);
704  ensurePolished();
705  QFontMetrics fm(font());
706  int h = qMax(fm.height(), 14) + 2*d->verticalMargin
707  + d->topTextMargin + d->bottomTextMargin
708  + d->topmargin + d->bottommargin;
709  int w = fm.width(QLatin1Char('x')) * 17 + 2*d->horizontalMargin
710  + d->leftTextMargin + d->rightTextMargin
711  + d->leftmargin + d->rightmargin; // "some"
713  initStyleOption(&opt);
714  return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h).
715  expandedTo(QApplication::globalStrut()), this));
716 }
double d
Definition: qnumeric_p.h:62
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
static QSize globalStrut()
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
void initStyleOption(QStyleOptionFrame *option) const
Initialize option with the values from this QLineEdit.
Definition: qlineedit.cpp:104
The QStyleOptionFrameV2 class is used to describe the parameters necessary for drawing a frame in Qt ...
Definition: qstyleoption.h:134
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
const QFont & font() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ text()

QString QLineEdit::text ( ) const

◆ textChanged

void QLineEdit::textChanged ( const QString text)
signal

This signal is emitted whenever the text changes.

The text argument is the new text.

Unlike textEdited(), this signal is also emitted when the text is changed programmatically, for example, by calling setText().

Referenced by QExpandingLineEdit::QExpandingLineEdit().

◆ textEdited

void QLineEdit::textEdited ( const QString text)
signal

This signal is emitted whenever the text is edited.

The text argument is the new text.

Unlike textChanged(), this signal is not emitted when the text is changed programmatically, for example, by calling setText().

◆ textMargins()

QMargins QLineEdit::textMargins ( ) const

Returns the widget's text margins.

Since
4.6
See also
setTextMargins()

Definition at line 1312 of file qlineedit.cpp.

1313 {
1314  Q_D(const QLineEdit);
1315  return QMargins(d->leftTextMargin, d->topTextMargin, d->rightTextMargin, d->bottomTextMargin);
1316 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:53

◆ undo

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.

Definition at line 1456 of file qlineedit.cpp.

Referenced by createStandardContextMenu().

1457 {
1458  Q_D(QLineEdit);
1460  d->control->undo();
1461 }
double d
Definition: qnumeric_p.h:62
void resetInputContext()
This function can be called on the widget that currently has focus to reset the input method operatin...
Definition: qwidget.cpp:522
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

◆ validator()

const QValidator * QLineEdit::validator ( ) const

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

See also
setValidator()

Definition at line 609 of file qlineedit.cpp.

610 {
611  Q_D(const QLineEdit);
612  return d->control->validator();
613 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66

Friends and Related Functions

◆ QAbstractSpinBox

friend class QAbstractSpinBox
friend

Definition at line 275 of file qlineedit.h.

◆ QAccessibleLineEdit

friend class QAccessibleLineEdit
friend

Definition at line 276 of file qlineedit.h.

Properties

◆ acceptableInput

QLineEdit::acceptableInput
private

whether the input satisfies the inputMask and the validator.

By default, this property is true.

See also
setInputMask(), setValidator()

Definition at line 86 of file qlineedit.h.

◆ alignment

Qt::Alignment QLineEdit::alignment
private

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

Definition at line 78 of file qlineedit.h.

◆ cursorMoveStyle

Qt::CursorMoveStyle QLineEdit::cursorMoveStyle
private

the movement style of cursor in this line edit

Returns the movement style for the cursor in the line edit.

Since
4.8

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.

Since
4.8

Definition at line 88 of file qlineedit.h.

◆ cursorPosition

int QLineEdit::cursorPosition
private

◆ displayText

QString QLineEdit::displayText
private

the displayed text

If echoMode is Normal this returns the same as text(); if EchoMode is Password or PasswordEchoOnEdit it returns a string of asterisks text().length() characters long, e.g. "******"; if EchoMode is NoEcho returns an empty string, "".

By default, this property contains an empty string.

See also
setEchoMode() text() EchoMode

Definition at line 76 of file qlineedit.h.

Referenced by QAbstractSpinBoxPrivate::interpret(), QAbstractSpinBox::setButtonSymbols(), and QAbstractSpinBoxPrivate::updateEdit().

◆ dragEnabled

bool QLineEdit::dragEnabled
private

whether the lineedit starts a drag if the user presses and moves the mouse on some selected text

Dragging is disabled by default.

Definition at line 82 of file qlineedit.h.

◆ echoMode

QLineEdit::EchoMode QLineEdit::echoMode
private

the line edit's echo mode

The echo mode determines how the text entered in the line edit is displayed (or echoed) to the user.

The most common setting is Normal , in which the text entered by the user is displayed verbatim, but QLineEdit also supports modes that allow the entered text to be suppressed or obscured: these include NoEcho , Password and PasswordEchoOnEdit .

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 Normal .

See also
EchoMode displayText()

Definition at line 75 of file qlineedit.h.

Referenced by QAccessibleLineEdit::state().

◆ frame

bool QLineEdit::frame
private

whether the line edit draws itself with a frame

Use hasFrame() instead.

If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame.

Definition at line 74 of file qlineedit.h.

◆ hasSelectedText

bool QLineEdit::hasSelectedText
private

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.

By default, this property is false.

See also
selectedText()

Definition at line 80 of file qlineedit.h.

Referenced by QDateTimeEditPrivate::_q_editorCursorPositionChanged(), QAbstractSpinBoxPrivate::_q_editorCursorPositionChanged(), QAccessibleLineEdit::selectionCount(), and QAccessibleLineEdit::state().

◆ inputMask

QString QLineEdit::inputMask
private

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 permitted but not required.

Character Meaning
A ASCII alphabetic character required. A-Z, a-z.
a ASCII alphabetic character permitted but not required.
N ASCII alphanumeric character required. A-Z, a-z, 0-9.
n ASCII alphanumeric character permitted but not required.
X Any character required.
x Any character permitted but not required.
9 ASCII digit required. 0-9.
0 ASCII digit permitted but not required.
D ASCII digit required. 1-9.
d ASCII digit permitted but not required (1-9).
# ASCII digit or plus/minus sign permitted but not required.
H Hexadecimal character required. A-F, a-f, 0-9.
h Hexadecimal character permitted but not required.
B Binary character required. 0-1.
b Binary 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 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:

Mask Notes
000.000.000.000;_ IP address; blanks are _.
HH:HH:HH:HH:HH:HH;_ MAC address
0000-00-00 ISO Date; blanks are space
>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# License number; blanks are - and all (alphabetic) characters are converted to uppercase.

To get range control (e.g., for an IP address) use masks together with validators.

See also
maxLength

Definition at line 71 of file qlineedit.h.

◆ maxLength

int QLineEdit::maxLength
private

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

Definition at line 73 of file qlineedit.h.

◆ modified

QLineEdit::modified
private

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.

Definition at line 79 of file qlineedit.h.

◆ placeholderText

QString QLineEdit::placeholderText
private

the line edit's placeholder text

Since
4.7

Setting this property makes the line edit display a grayed-out placeholder text as long as the text() is empty and the widget doesn't have focus.

By default, this property contains an empty string.

See also
text()

Definition at line 87 of file qlineedit.h.

◆ readOnly

QLineEdit::readOnly
private

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 Normal ), but cannot edit it.

QLineEdit does not show a cursor in read-only mode.

By default, this property is false.

See also
setEnabled()

Definition at line 83 of file qlineedit.h.

◆ redoAvailable

QLineEdit::redoAvailable
private

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.

Definition at line 85 of file qlineedit.h.

◆ selectedText

QString QLineEdit::selectedText
private

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()

Definition at line 81 of file qlineedit.h.

Referenced by QDateTimeEditPrivate::_q_editorCursorPositionChanged(), QAbstractSpinBoxPrivate::_q_editorCursorPositionChanged(), QAccessibleLineEdit::selection(), QDateTimeEditPrivate::updateEdit(), and QAbstractSpinBoxPrivate::updateEdit().

◆ text

QString QLineEdit::text
private

◆ undoAvailable

QLineEdit::undoAvailable
private

whether undo is available

Undo becomes available once the user has modified the text in the line edit.

By default, this property is false.

Definition at line 84 of file qlineedit.h.


The documentation for this class was generated from the following files: