class_lineedit.rst 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the LineEdit.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_LineEdit:
  6. LineEdit
  7. ========
  8. **Inherits:** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. Control that provides single-line string editing.
  10. Description
  11. -----------
  12. LineEdit provides a single-line string editor, used for text fields. It features many built-in shortcuts which will always be available: (the Ctrl here maps to Command on macOS)
  13. - Ctrl + C: Copy
  14. - Ctrl + X: Cut
  15. - Ctrl + V or Ctrl + Y: Paste/"yank"
  16. - Ctrl + Z: Undo
  17. - Ctrl + Shift + Z: Redo
  18. - Ctrl + U: Delete text from the cursor position to the beginning of the line
  19. - Ctrl + K: Delete text from the cursor position to the end of the line
  20. - Ctrl + A: Select all text
  21. - Up/Down arrow: Move the cursor to the beginning/end of the line
  22. On macOS, some extra keyboard shortcuts are available:
  23. - Ctrl + F: Like the right arrow key, move the cursor one character right
  24. - Ctrl + B: Like the left arrow key, move the cursor one character left
  25. - Ctrl + P: Like the up arrow key, move the cursor to the previous line
  26. - Ctrl + N: Like the down arrow key, move the cursor to the next line
  27. - Ctrl + D: Like the Delete key, delete the character on the right side of cursor
  28. - Ctrl + H: Like the Backspace key, delete the character on the left side of the cursor
  29. - Command + Left arrow: Like the Home key, move the cursor to the beginning of the line
  30. - Command + Right arrow: Like the End key, move the cursor to the end of the line
  31. Properties
  32. ----------
  33. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  34. | :ref:`Align<enum_LineEdit_Align>` | :ref:`align<class_LineEdit_property_align>` | 0 |
  35. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  36. | :ref:`bool<class_bool>` | :ref:`caret_blink<class_LineEdit_property_caret_blink>` | false |
  37. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  38. | :ref:`float<class_float>` | :ref:`caret_blink_speed<class_LineEdit_property_caret_blink_speed>` | 0.65 |
  39. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  40. | :ref:`int<class_int>` | :ref:`caret_position<class_LineEdit_property_caret_position>` | 0 |
  41. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  42. | :ref:`bool<class_bool>` | :ref:`clear_button_enabled<class_LineEdit_property_clear_button_enabled>` | false |
  43. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  44. | :ref:`bool<class_bool>` | :ref:`context_menu_enabled<class_LineEdit_property_context_menu_enabled>` | true |
  45. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  46. | :ref:`bool<class_bool>` | :ref:`editable<class_LineEdit_property_editable>` | true |
  47. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  48. | :ref:`bool<class_bool>` | :ref:`expand_to_text_length<class_LineEdit_property_expand_to_text_length>` | false |
  49. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  50. | :ref:`FocusMode<enum_Control_FocusMode>` | focus_mode | **O:** 2 |
  51. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  52. | :ref:`int<class_int>` | :ref:`max_length<class_LineEdit_property_max_length>` | 0 |
  53. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  54. | :ref:`CursorShape<enum_Control_CursorShape>` | mouse_default_cursor_shape | **O:** 1 |
  55. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  56. | :ref:`float<class_float>` | :ref:`placeholder_alpha<class_LineEdit_property_placeholder_alpha>` | 0.6 |
  57. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  58. | :ref:`String<class_String>` | :ref:`placeholder_text<class_LineEdit_property_placeholder_text>` | "" |
  59. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  60. | :ref:`Texture<class_Texture>` | :ref:`right_icon<class_LineEdit_property_right_icon>` | |
  61. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  62. | :ref:`bool<class_bool>` | :ref:`secret<class_LineEdit_property_secret>` | false |
  63. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  64. | :ref:`String<class_String>` | :ref:`secret_character<class_LineEdit_property_secret_character>` | "\*" |
  65. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  66. | :ref:`bool<class_bool>` | :ref:`selecting_enabled<class_LineEdit_property_selecting_enabled>` | true |
  67. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  68. | :ref:`bool<class_bool>` | :ref:`shortcut_keys_enabled<class_LineEdit_property_shortcut_keys_enabled>` | true |
  69. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  70. | :ref:`String<class_String>` | :ref:`text<class_LineEdit_property_text>` | "" |
  71. +----------------------------------------------+-----------------------------------------------------------------------------+----------+
  72. Methods
  73. -------
  74. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`append_at_cursor<class_LineEdit_method_append_at_cursor>` **(** :ref:`String<class_String>` text **)** |
  76. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`clear<class_LineEdit_method_clear>` **(** **)** |
  78. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`deselect<class_LineEdit_method_deselect>` **(** **)** |
  80. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_menu<class_LineEdit_method_get_menu>` **(** **)** const |
  82. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  83. | void | :ref:`menu_option<class_LineEdit_method_menu_option>` **(** :ref:`int<class_int>` option **)** |
  84. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  85. | void | :ref:`select<class_LineEdit_method_select>` **(** :ref:`int<class_int>` from=0, :ref:`int<class_int>` to=-1 **)** |
  86. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  87. | void | :ref:`select_all<class_LineEdit_method_select_all>` **(** **)** |
  88. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------+
  89. Theme Properties
  90. ----------------
  91. +---------------------------------+----------------------------+--------------------------------+
  92. | :ref:`Texture<class_Texture>` | clear | |
  93. +---------------------------------+----------------------------+--------------------------------+
  94. | :ref:`Color<class_Color>` | clear_button_color | Color( 0.88, 0.88, 0.88, 1 ) |
  95. +---------------------------------+----------------------------+--------------------------------+
  96. | :ref:`Color<class_Color>` | clear_button_color_pressed | Color( 1, 1, 1, 1 ) |
  97. +---------------------------------+----------------------------+--------------------------------+
  98. | :ref:`Color<class_Color>` | cursor_color | Color( 0.94, 0.94, 0.94, 1 ) |
  99. +---------------------------------+----------------------------+--------------------------------+
  100. | :ref:`StyleBox<class_StyleBox>` | focus | |
  101. +---------------------------------+----------------------------+--------------------------------+
  102. | :ref:`Font<class_Font>` | font | |
  103. +---------------------------------+----------------------------+--------------------------------+
  104. | :ref:`Color<class_Color>` | font_color | Color( 0.88, 0.88, 0.88, 1 ) |
  105. +---------------------------------+----------------------------+--------------------------------+
  106. | :ref:`Color<class_Color>` | font_color_selected | Color( 0, 0, 0, 1 ) |
  107. +---------------------------------+----------------------------+--------------------------------+
  108. | :ref:`Color<class_Color>` | font_color_uneditable | Color( 0.88, 0.88, 0.88, 0.5 ) |
  109. +---------------------------------+----------------------------+--------------------------------+
  110. | :ref:`int<class_int>` | minimum_spaces | 12 |
  111. +---------------------------------+----------------------------+--------------------------------+
  112. | :ref:`StyleBox<class_StyleBox>` | normal | |
  113. +---------------------------------+----------------------------+--------------------------------+
  114. | :ref:`StyleBox<class_StyleBox>` | read_only | |
  115. +---------------------------------+----------------------------+--------------------------------+
  116. | :ref:`Color<class_Color>` | selection_color | Color( 0.49, 0.49, 0.49, 1 ) |
  117. +---------------------------------+----------------------------+--------------------------------+
  118. Signals
  119. -------
  120. .. _class_LineEdit_signal_text_change_rejected:
  121. - **text_change_rejected** **(** **)**
  122. Emitted when trying to append text that would overflow the :ref:`max_length<class_LineEdit_property_max_length>`.
  123. ----
  124. .. _class_LineEdit_signal_text_changed:
  125. - **text_changed** **(** :ref:`String<class_String>` new_text **)**
  126. Emitted when the text changes.
  127. ----
  128. .. _class_LineEdit_signal_text_entered:
  129. - **text_entered** **(** :ref:`String<class_String>` new_text **)**
  130. Emitted when the user presses :ref:`@GlobalScope.KEY_ENTER<class_@GlobalScope_constant_KEY_ENTER>` on the ``LineEdit``.
  131. Enumerations
  132. ------------
  133. .. _enum_LineEdit_Align:
  134. .. _class_LineEdit_constant_ALIGN_LEFT:
  135. .. _class_LineEdit_constant_ALIGN_CENTER:
  136. .. _class_LineEdit_constant_ALIGN_RIGHT:
  137. .. _class_LineEdit_constant_ALIGN_FILL:
  138. enum **Align**:
  139. - **ALIGN_LEFT** = **0** --- Aligns the text on the left-hand side of the ``LineEdit``.
  140. - **ALIGN_CENTER** = **1** --- Centers the text in the middle of the ``LineEdit``.
  141. - **ALIGN_RIGHT** = **2** --- Aligns the text on the right-hand side of the ``LineEdit``.
  142. - **ALIGN_FILL** = **3** --- Stretches whitespaces to fit the ``LineEdit``'s width.
  143. ----
  144. .. _enum_LineEdit_MenuItems:
  145. .. _class_LineEdit_constant_MENU_CUT:
  146. .. _class_LineEdit_constant_MENU_COPY:
  147. .. _class_LineEdit_constant_MENU_PASTE:
  148. .. _class_LineEdit_constant_MENU_CLEAR:
  149. .. _class_LineEdit_constant_MENU_SELECT_ALL:
  150. .. _class_LineEdit_constant_MENU_UNDO:
  151. .. _class_LineEdit_constant_MENU_REDO:
  152. .. _class_LineEdit_constant_MENU_MAX:
  153. enum **MenuItems**:
  154. - **MENU_CUT** = **0** --- Cuts (copies and clears) the selected text.
  155. - **MENU_COPY** = **1** --- Copies the selected text.
  156. - **MENU_PASTE** = **2** --- Pastes the clipboard text over the selected text (or at the cursor's position).
  157. Non-printable escape characters are automatically stripped from the OS clipboard via :ref:`String.strip_escapes<class_String_method_strip_escapes>`.
  158. - **MENU_CLEAR** = **3** --- Erases the whole ``LineEdit`` text.
  159. - **MENU_SELECT_ALL** = **4** --- Selects the whole ``LineEdit`` text.
  160. - **MENU_UNDO** = **5** --- Undoes the previous action.
  161. - **MENU_REDO** = **6** --- Reverse the last undo action.
  162. - **MENU_MAX** = **7** --- Represents the size of the :ref:`MenuItems<enum_LineEdit_MenuItems>` enum.
  163. Property Descriptions
  164. ---------------------
  165. .. _class_LineEdit_property_align:
  166. - :ref:`Align<enum_LineEdit_Align>` **align**
  167. +-----------+------------------+
  168. | *Default* | 0 |
  169. +-----------+------------------+
  170. | *Setter* | set_align(value) |
  171. +-----------+------------------+
  172. | *Getter* | get_align() |
  173. +-----------+------------------+
  174. Text alignment as defined in the :ref:`Align<enum_LineEdit_Align>` enum.
  175. ----
  176. .. _class_LineEdit_property_caret_blink:
  177. - :ref:`bool<class_bool>` **caret_blink**
  178. +-----------+---------------------------------+
  179. | *Default* | false |
  180. +-----------+---------------------------------+
  181. | *Setter* | cursor_set_blink_enabled(value) |
  182. +-----------+---------------------------------+
  183. | *Getter* | cursor_get_blink_enabled() |
  184. +-----------+---------------------------------+
  185. If ``true``, the caret (visual cursor) blinks.
  186. ----
  187. .. _class_LineEdit_property_caret_blink_speed:
  188. - :ref:`float<class_float>` **caret_blink_speed**
  189. +-----------+-------------------------------+
  190. | *Default* | 0.65 |
  191. +-----------+-------------------------------+
  192. | *Setter* | cursor_set_blink_speed(value) |
  193. +-----------+-------------------------------+
  194. | *Getter* | cursor_get_blink_speed() |
  195. +-----------+-------------------------------+
  196. Duration (in seconds) of a caret's blinking cycle.
  197. ----
  198. .. _class_LineEdit_property_caret_position:
  199. - :ref:`int<class_int>` **caret_position**
  200. +-----------+----------------------------+
  201. | *Default* | 0 |
  202. +-----------+----------------------------+
  203. | *Setter* | set_cursor_position(value) |
  204. +-----------+----------------------------+
  205. | *Getter* | get_cursor_position() |
  206. +-----------+----------------------------+
  207. The cursor's position inside the ``LineEdit``. When set, the text may scroll to accommodate it.
  208. ----
  209. .. _class_LineEdit_property_clear_button_enabled:
  210. - :ref:`bool<class_bool>` **clear_button_enabled**
  211. +-----------+---------------------------------+
  212. | *Default* | false |
  213. +-----------+---------------------------------+
  214. | *Setter* | set_clear_button_enabled(value) |
  215. +-----------+---------------------------------+
  216. | *Getter* | is_clear_button_enabled() |
  217. +-----------+---------------------------------+
  218. If ``true``, the ``LineEdit`` will show a clear button if ``text`` is not empty, which can be used to clear the text quickly.
  219. ----
  220. .. _class_LineEdit_property_context_menu_enabled:
  221. - :ref:`bool<class_bool>` **context_menu_enabled**
  222. +-----------+---------------------------------+
  223. | *Default* | true |
  224. +-----------+---------------------------------+
  225. | *Setter* | set_context_menu_enabled(value) |
  226. +-----------+---------------------------------+
  227. | *Getter* | is_context_menu_enabled() |
  228. +-----------+---------------------------------+
  229. If ``true``, the context menu will appear when right-clicked.
  230. ----
  231. .. _class_LineEdit_property_editable:
  232. - :ref:`bool<class_bool>` **editable**
  233. +-----------+---------------------+
  234. | *Default* | true |
  235. +-----------+---------------------+
  236. | *Setter* | set_editable(value) |
  237. +-----------+---------------------+
  238. | *Getter* | is_editable() |
  239. +-----------+---------------------+
  240. If ``false``, existing text cannot be modified and new text cannot be added.
  241. ----
  242. .. _class_LineEdit_property_expand_to_text_length:
  243. - :ref:`bool<class_bool>` **expand_to_text_length**
  244. +-----------+----------------------------------+
  245. | *Default* | false |
  246. +-----------+----------------------------------+
  247. | *Setter* | set_expand_to_text_length(value) |
  248. +-----------+----------------------------------+
  249. | *Getter* | get_expand_to_text_length() |
  250. +-----------+----------------------------------+
  251. If ``true``, the ``LineEdit`` width will increase to stay longer than the :ref:`text<class_LineEdit_property_text>`. It will **not** compress if the :ref:`text<class_LineEdit_property_text>` is shortened.
  252. ----
  253. .. _class_LineEdit_property_max_length:
  254. - :ref:`int<class_int>` **max_length**
  255. +-----------+-----------------------+
  256. | *Default* | 0 |
  257. +-----------+-----------------------+
  258. | *Setter* | set_max_length(value) |
  259. +-----------+-----------------------+
  260. | *Getter* | get_max_length() |
  261. +-----------+-----------------------+
  262. Maximum amount of characters that can be entered inside the ``LineEdit``. If ``0``, there is no limit.
  263. ----
  264. .. _class_LineEdit_property_placeholder_alpha:
  265. - :ref:`float<class_float>` **placeholder_alpha**
  266. +-----------+------------------------------+
  267. | *Default* | 0.6 |
  268. +-----------+------------------------------+
  269. | *Setter* | set_placeholder_alpha(value) |
  270. +-----------+------------------------------+
  271. | *Getter* | get_placeholder_alpha() |
  272. +-----------+------------------------------+
  273. Opacity of the :ref:`placeholder_text<class_LineEdit_property_placeholder_text>`. From ``0`` to ``1``.
  274. ----
  275. .. _class_LineEdit_property_placeholder_text:
  276. - :ref:`String<class_String>` **placeholder_text**
  277. +-----------+------------------------+
  278. | *Default* | "" |
  279. +-----------+------------------------+
  280. | *Setter* | set_placeholder(value) |
  281. +-----------+------------------------+
  282. | *Getter* | get_placeholder() |
  283. +-----------+------------------------+
  284. Text shown when the ``LineEdit`` is empty. It is **not** the ``LineEdit``'s default value (see :ref:`text<class_LineEdit_property_text>`).
  285. ----
  286. .. _class_LineEdit_property_right_icon:
  287. - :ref:`Texture<class_Texture>` **right_icon**
  288. +----------+-----------------------+
  289. | *Setter* | set_right_icon(value) |
  290. +----------+-----------------------+
  291. | *Getter* | get_right_icon() |
  292. +----------+-----------------------+
  293. Sets the icon that will appear in the right end of the ``LineEdit`` if there's no :ref:`text<class_LineEdit_property_text>`, or always, if :ref:`clear_button_enabled<class_LineEdit_property_clear_button_enabled>` is set to ``false``.
  294. ----
  295. .. _class_LineEdit_property_secret:
  296. - :ref:`bool<class_bool>` **secret**
  297. +-----------+-------------------+
  298. | *Default* | false |
  299. +-----------+-------------------+
  300. | *Setter* | set_secret(value) |
  301. +-----------+-------------------+
  302. | *Getter* | is_secret() |
  303. +-----------+-------------------+
  304. If ``true``, every character is replaced with the secret character (see :ref:`secret_character<class_LineEdit_property_secret_character>`).
  305. ----
  306. .. _class_LineEdit_property_secret_character:
  307. - :ref:`String<class_String>` **secret_character**
  308. +-----------+-----------------------------+
  309. | *Default* | "\*" |
  310. +-----------+-----------------------------+
  311. | *Setter* | set_secret_character(value) |
  312. +-----------+-----------------------------+
  313. | *Getter* | get_secret_character() |
  314. +-----------+-----------------------------+
  315. The character to use to mask secret input (defaults to "\*"). Only a single character can be used as the secret character.
  316. ----
  317. .. _class_LineEdit_property_selecting_enabled:
  318. - :ref:`bool<class_bool>` **selecting_enabled**
  319. +-----------+------------------------------+
  320. | *Default* | true |
  321. +-----------+------------------------------+
  322. | *Setter* | set_selecting_enabled(value) |
  323. +-----------+------------------------------+
  324. | *Getter* | is_selecting_enabled() |
  325. +-----------+------------------------------+
  326. If ``false``, it's impossible to select the text using mouse nor keyboard.
  327. ----
  328. .. _class_LineEdit_property_shortcut_keys_enabled:
  329. - :ref:`bool<class_bool>` **shortcut_keys_enabled**
  330. +-----------+----------------------------------+
  331. | *Default* | true |
  332. +-----------+----------------------------------+
  333. | *Setter* | set_shortcut_keys_enabled(value) |
  334. +-----------+----------------------------------+
  335. | *Getter* | is_shortcut_keys_enabled() |
  336. +-----------+----------------------------------+
  337. If ``false``, using shortcuts will be disabled.
  338. ----
  339. .. _class_LineEdit_property_text:
  340. - :ref:`String<class_String>` **text**
  341. +-----------+-----------------+
  342. | *Default* | "" |
  343. +-----------+-----------------+
  344. | *Setter* | set_text(value) |
  345. +-----------+-----------------+
  346. | *Getter* | get_text() |
  347. +-----------+-----------------+
  348. String value of the ``LineEdit``.
  349. **Note:** Changing text using this property won't emit the :ref:`text_changed<class_LineEdit_signal_text_changed>` signal.
  350. Method Descriptions
  351. -------------------
  352. .. _class_LineEdit_method_append_at_cursor:
  353. - void **append_at_cursor** **(** :ref:`String<class_String>` text **)**
  354. Adds ``text`` after the cursor. If the resulting value is longer than :ref:`max_length<class_LineEdit_property_max_length>`, nothing happens.
  355. ----
  356. .. _class_LineEdit_method_clear:
  357. - void **clear** **(** **)**
  358. Erases the ``LineEdit`` text.
  359. ----
  360. .. _class_LineEdit_method_deselect:
  361. - void **deselect** **(** **)**
  362. Clears the current selection.
  363. ----
  364. .. _class_LineEdit_method_get_menu:
  365. - :ref:`PopupMenu<class_PopupMenu>` **get_menu** **(** **)** const
  366. Returns the :ref:`PopupMenu<class_PopupMenu>` of this ``LineEdit``. By default, this menu is displayed when right-clicking on the ``LineEdit``.
  367. ----
  368. .. _class_LineEdit_method_menu_option:
  369. - void **menu_option** **(** :ref:`int<class_int>` option **)**
  370. Executes a given action as defined in the :ref:`MenuItems<enum_LineEdit_MenuItems>` enum.
  371. ----
  372. .. _class_LineEdit_method_select:
  373. - void **select** **(** :ref:`int<class_int>` from=0, :ref:`int<class_int>` to=-1 **)**
  374. Selects characters inside ``LineEdit`` between ``from`` and ``to``. By default, ``from`` is at the beginning and ``to`` at the end.
  375. ::
  376. text = "Welcome"
  377. select() # Will select "Welcome"
  378. select(4) # Will select "ome"
  379. select(2, 5) # Will select "lco"
  380. ----
  381. .. _class_LineEdit_method_select_all:
  382. - void **select_all** **(** **)**
  383. Selects the whole :ref:`String<class_String>`.