TextField QML Type
单行文本输入框。更多
Import Statement: | import QtQuick.Controls |
Inherits: |
属性
- background : Item
- bottomInset : real
(since QtQuick.Controls 2.5 (Qt 5.12))
- focusReason : enumeration
- hoverEnabled : bool
(since QtQuick.Controls 2.1 (Qt 5.8))
- hovered : bool
(since QtQuick.Controls 2.1 (Qt 5.8))
- implicitBackgroundHeight : real
(since QtQuick.Controls 2.5 (Qt 5.12))
- implicitBackgroundWidth : real
(since QtQuick.Controls 2.5 (Qt 5.12))
- leftInset : real
(since QtQuick.Controls 2.5 (Qt 5.12))
- placeholderText : string
- placeholderTextColor : color
(since QtQuick.Controls 2.5 (Qt 5.12))
- rightInset : real
(since QtQuick.Controls 2.5 (Qt 5.12))
- topInset : real
(since QtQuick.Controls 2.5 (Qt 5.12))
信号
- pressAndHold(MouseEvent event)
- pressed(MouseEvent event)
(since QtQuick.Controls 2.1 (Qt 5.8))
- released(MouseEvent event)
(since QtQuick.Controls 2.1 (Qt 5.8))
详细说明
TextField 是一个单行文本编辑器。TextField 通过placeholder text 功能扩展了TextInput ,并添加了装饰。
正常状态下的文本字段。 | |
具有活动焦点的文本字段。 | |
禁用的文本字段。 |
TextField { placeholderText: qsTr("Enter name") }
另请参阅 TextArea 、自定义 TextField 和输入控件。
属性文档
background : Item |
bottomInset : real |
focusReason : enumeration |
该属性显示上次焦点改变的原因。
注意: 该属性并不表示项目是否active focus ,而是表示项目获得或失去焦点的原因。
常量 | 说明 |
---|---|
Qt.MouseFocusReason | 发生了鼠标操作。 |
Qt.TabFocusReason | 按了 Tab 键。 |
Qt.BacktabFocusReason | 出现 Backtab。输入可能包括 Shift 或 Control 键,如 Shift+Tab。 |
Qt.ActiveWindowFocusReason | 窗口系统使该窗口处于活动或非活动状态。 |
Qt.PopupFocusReason | 应用程序打开/关闭了一个弹出窗口,该窗口抓住/释放了键盘焦点。 |
Qt.ShortcutFocusReason | 用户键入标签的好友快捷键 |
Qt.MenuBarFocusReason | 菜单栏占用焦点。 |
Qt.OtherFocusReason | 其他原因,通常与应用程序有关。 |
hoverEnabled : bool |
hovered : bool |
implicitBackgroundHeight : real |
该属性表示隐式背景高度。
其值等于background ? background.implicitHeight : 0
。
该属性在 QtQuick.Controls 2.5 (Qt 5.12) 中引入。
另请参阅 implicitBackgroundWidth 。
implicitBackgroundWidth : real |
该属性保存隐式背景宽度。
其值等于background ? background.implicitWidth : 0
。
该属性在 QtQuick.Controls 2.5 (Qt 5.12) 中引入。
另请参阅 implicitBackgroundHeight 。
leftInset : real |
placeholderTextColor : color |
rightInset : real |
topInset : real |
信号文档
pressAndHold(MouseEvent event) |
|
当用户按下文本字段时会发出该信号。event 参数提供了有关按压的信息,包括按压的 x 坐标和 y 坐标,以及按压的按钮。
注: 相应的处理程序是onPressed
。
该信号在 QtQuick.Controls 2.1 (Qt 5.8) 中引入。
另请参阅 released 和pressAndHold 。
|
该信号在用户释放文本字段时发出。event 参数提供了有关释放的信息,包括按下时的 x 坐标和 y 坐标,以及按下了哪个按钮。
注: 相应的处理程序是onReleased
。
该信号在 QtQuick.Controls 2.1 (Qt 5.8) 中引入。
另请参阅 pressed 和pressAndHold 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.