Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

LineEdit

繼承: Control < CanvasItem < Node < Object

單行文字的輸入欄位。

說明

LineEdit provides an input field for editing a single line of text.

  • When the LineEdit control is focused using the keyboard arrow keys, it will only gain focus and not enter edit mode.

  • To enter edit mode, click on the control with the mouse, see also keep_editing_on_text_submit.

  • To exit edit mode, press ui_text_submit or ui_cancel (by default Escape) actions.

  • Check edit(), unedit(), is_editing(), and editing_toggled for more information.

While entering text, it is possible to insert special characters using Unicode, OEM or Windows alt codes:

  • To enter Unicode codepoints, hold Alt and type the codepoint on the numpad. For example, to enter the character á (U+00E1), hold Alt and type +E1 on the numpad (the leading zeroes can be omitted).

  • To enter OEM codepoints, hold Alt and type the code on the numpad. For example, to enter the character á (OEM 160), hold Alt and type 160 on the numpad.

  • To enter Windows codepoints, hold Alt and type the code on the numpad. For example, to enter the character á (Windows 0225), hold Alt and type 0, 2, 2, 5 on the numpad. The leading zero here must not be omitted, as this is how Windows codepoints are distinguished from OEM codepoints.

Important:

  • Focusing the LineEdit with ui_focus_next (by default Tab) or ui_focus_prev (by default Shift + Tab) or Control.grab_focus() still enters edit mode (for compatibility).

LineEdit features many built-in shortcuts that are always available (Ctrl here maps to Cmd on macOS):

  • Ctrl + C: Copy

  • Ctrl + X: Cut

  • Ctrl + V or Ctrl + Y: Paste/"yank"

  • Ctrl + Z: Undo

  • Ctrl + ~: Swap input direction.

  • Ctrl + Shift + Z: Redo

  • Ctrl + U: Delete text from the caret position to the beginning of the line

  • Ctrl + K: Delete text from the caret position to the end of the line

  • Ctrl + A: Select all text

  • Up Arrow/Down Arrow: Move the caret to the beginning/end of the line

On macOS, some extra keyboard shortcuts are available:

  • Cmd + F: Same as Right Arrow, move the caret one character right

  • Cmd + B: Same as Left Arrow, move the caret one character left

  • Cmd + P: Same as Up Arrow, move the caret to the previous line

  • Cmd + N: Same as Down Arrow, move the caret to the next line

  • Cmd + D: Same as Delete, delete the character on the right side of caret

  • Cmd + H: Same as Backspace, delete the character on the left side of the caret

  • Cmd + A: Same as Home, move the caret to the beginning of the line

  • Cmd + E: Same as End, move the caret to the end of the line

  • Cmd + Left Arrow: Same as Home, move the caret to the beginning of the line

  • Cmd + Right Arrow: Same as End, move the caret to the end of the line

Note: Caret movement shortcuts listed above are not affected by shortcut_keys_enabled.

屬性

HorizontalAlignment

alignment

0

bool

backspace_deletes_composite_character_enabled

false

bool

caret_blink

false

float

caret_blink_interval

0.65

int

caret_column

0

bool

caret_force_displayed

false

bool

caret_mid_grapheme

false

bool

clear_button_enabled

false

bool

context_menu_enabled

true

bool

deselect_on_focus_loss_enabled

true

bool

drag_and_drop_selection_enabled

true

bool

draw_control_chars

false

bool

editable

true

bool

emoji_menu_enabled

true

bool

expand_to_text_length

false

bool

flat

false

FocusMode

focus_mode

2 (overrides Control)

ExpandMode

icon_expand_mode

0

bool

keep_editing_on_text_submit

false

String

language

""

int

max_length

0

bool

middle_mouse_paste_enabled

true

CursorShape

mouse_default_cursor_shape

1 (overrides Control)

String

placeholder_text

""

Texture2D

right_icon

float

right_icon_scale

1.0

bool

secret

false

String

secret_character

"•"

bool

select_all_on_focus

false

bool

selecting_enabled

true

bool

shortcut_keys_enabled

true

StructuredTextParser

structured_text_bidi_override

0

Array

structured_text_bidi_override_options

[]

String

text

""

TextDirection

text_direction

0

bool

virtual_keyboard_enabled

true

bool

virtual_keyboard_show_on_focus

true

VirtualKeyboardType

virtual_keyboard_type

0

方法

void

apply_ime()

void

cancel_ime()

void

clear()

void

delete_char_at_caret()

void

delete_text(from_column: int, to_column: int)

void

deselect()

void

edit(hide_focus: bool = false)

PopupMenu

get_menu() const

int

get_next_composite_character_column(column: int) const

int

get_previous_composite_character_column(column: int) const

float

get_scroll_offset() const

String

get_selected_text()

int

get_selection_from_column() const

int

get_selection_to_column() const

bool

has_ime_text() const

bool

has_redo() const

bool

has_selection() const

bool

has_undo() const

void

insert_text_at_caret(text: String)

bool

is_editing() const

bool

is_menu_visible() const

void

menu_option(option: int)

void

select(from: int = 0, to: int = -1)

void

select_all()

void

unedit()

主題屬性

Color

caret_color

Color(0.95, 0.95, 0.95, 1)

Color

clear_button_color

Color(0.875, 0.875, 0.875, 1)

Color

clear_button_color_pressed

Color(1, 1, 1, 1)

Color

font_color

Color(0.875, 0.875, 0.875, 1)

Color

font_outline_color

Color(0, 0, 0, 1)

Color

font_placeholder_color

Color(0.875, 0.875, 0.875, 0.6)

Color

font_selected_color

Color(1, 1, 1, 1)

Color

font_uneditable_color

Color(0.875, 0.875, 0.875, 0.5)

Color

selection_color

Color(0.5, 0.5, 0.5, 1)

int

caret_width

1

int

minimum_character_width

4

int

outline_size

0

Font

font

int

font_size

Texture2D

clear

StyleBox

focus

StyleBox

normal

StyleBox

read_only


訊號

editing_toggled(toggled_on: bool) 🔗

Emitted when the LineEdit switches in or out of edit mode.


text_change_rejected(rejected_substring: String) 🔗

當追加的文字超過了 max_length 時觸發。追加後的文字會被截斷以適應 max_length,超出的部分會被作為 rejected_substring 參數傳遞。


text_changed(new_text: String) 🔗

當文字更改時觸發。


text_submitted(new_text: String) 🔗

Emitted when the user presses the ui_text_submit action (by default: Enter or Kp Enter) while the LineEdit has focus.


列舉

enum MenuItems: 🔗

MenuItems MENU_CUT = 0

剪切(複製並刪除)選中的文字。

MenuItems MENU_COPY = 1

複製選中的文字。

MenuItems MENU_PASTE = 2

將剪貼板中的文字貼上到選中文字之上(或者文字游標位置)。

會使用 String.strip_escapes() 自動剝離作業系統剪貼板中不可列印的轉義字符。

MenuItems MENU_CLEAR = 3

刪除 LineEdit 中的全部文字。

MenuItems MENU_SELECT_ALL = 4

選中 LineEdit 中的全部文字。

MenuItems MENU_UNDO = 5

撤銷之前的操作。

MenuItems MENU_REDO = 6

反轉最後一個撤銷動作。

MenuItems MENU_SUBMENU_TEXT_DIR = 7

“文字書寫方向”子功能表的 ID。

MenuItems MENU_DIR_INHERITED = 8

將文字方向設定為繼承。

MenuItems MENU_DIR_AUTO = 9

將文字方向設定為自動。

MenuItems MENU_DIR_LTR = 10

將文字方向設定為從左至右。

MenuItems MENU_DIR_RTL = 11

將文字方向設定為從右至左。

MenuItems MENU_DISPLAY_UCC = 12

切換控制字元的顯示。

MenuItems MENU_SUBMENU_INSERT_UCC = 13

“插入控制字元”子功能表的 ID。

MenuItems MENU_INSERT_LRM = 14

插入從左至右旗標(LRM)字元。

MenuItems MENU_INSERT_RLM = 15

插入從右至左旗標(LRM)字元。

MenuItems MENU_INSERT_LRE = 16

插入開始從左至右嵌入(LRE)字元。

MenuItems MENU_INSERT_RLE = 17

插入開始從右至左嵌入(RLE)字元。

MenuItems MENU_INSERT_LRO = 18

插入開始從左至右強制(LRO)字元。

MenuItems MENU_INSERT_RLO = 19

插入開始從右至左嵌入(RLE)字元。

MenuItems MENU_INSERT_PDF = 20

插入退出方向格式化(PDF)字元。

MenuItems MENU_INSERT_ALM = 21

插入阿拉伯字母標記(ALM)字元。

MenuItems MENU_INSERT_LRI = 22

插入從左至右隔離(LRI)字元。

MenuItems MENU_INSERT_RLI = 23

插入從右至左隔離(RLI)字元。

MenuItems MENU_INSERT_FSI = 24

插入第一個強隔離(FSI)字元。

MenuItems MENU_INSERT_PDI = 25

插入退出方向隔離(PDI)字元。

MenuItems MENU_INSERT_ZWJ = 26

插入零寬連接子(ZWJ)字元。

MenuItems MENU_INSERT_ZWNJ = 27

插入零寬非連接子(ZWNJ)字元。

MenuItems MENU_INSERT_WJ = 28

插入文字連接子(WJ)字元。

MenuItems MENU_INSERT_SHY = 29

插入軟連字號(SHY)字元。

MenuItems MENU_EMOJI_AND_SYMBOL = 30

Opens system emoji and symbol picker.

MenuItems MENU_MAX = 31

代表 MenuItems 列舉的大小。


enum VirtualKeyboardType: 🔗

VirtualKeyboardType KEYBOARD_TYPE_DEFAULT = 0

預設文字虛擬鍵盤。

VirtualKeyboardType KEYBOARD_TYPE_MULTILINE = 1

多行虛擬鍵盤。

VirtualKeyboardType KEYBOARD_TYPE_NUMBER = 2

虛擬數位鍵盤,可用於 PIN 輸入。

VirtualKeyboardType KEYBOARD_TYPE_NUMBER_DECIMAL = 3

虛擬數位鍵盤,可用於輸入小數。

VirtualKeyboardType KEYBOARD_TYPE_PHONE = 4

虛擬手機號碼鍵盤。

VirtualKeyboardType KEYBOARD_TYPE_EMAIL_ADDRESS = 5

帶有附加鍵的虛擬鍵盤,可説明輸入電子郵寄地址。

VirtualKeyboardType KEYBOARD_TYPE_PASSWORD = 6

用於輸入密碼的虛擬鍵盤。在大多數平臺上,這應該會禁用自動完成和自動首字母大寫功能。

注意:Web 平臺不支援。與 KEYBOARD_TYPE_DEFAULT 的行為相同。

VirtualKeyboardType KEYBOARD_TYPE_URL = 7

帶有附加鍵的虛擬鍵盤,可説明輸入 URL。


enum ExpandMode: 🔗

ExpandMode EXPAND_MODE_ORIGINAL_SIZE = 0

Use the original size for the right icon.

ExpandMode EXPAND_MODE_FIT_TO_TEXT = 1

Scale the right icon's size to match the size of the text.

ExpandMode EXPAND_MODE_FIT_TO_LINE_EDIT = 2

Scale the right icon to fit the LineEdit.


屬性說明

HorizontalAlignment alignment = 0 🔗

The text's horizontal alignment.


bool backspace_deletes_composite_character_enabled = false 🔗

  • void set_backspace_deletes_composite_character_enabled(value: bool)

  • bool is_backspace_deletes_composite_character_enabled()

If true and caret_mid_grapheme is false, backspace deletes an entire composite character such as ❤️‍🩹, instead of deleting part of the composite character.


  • void set_caret_blink_enabled(value: bool)

  • bool is_caret_blink_enabled()

如果為 true,則文字游標會閃爍。


  • void set_caret_blink_interval(value: float)

  • float get_caret_blink_interval()

文字游標的閃爍間隔(單位為秒)。


int caret_column = 0 🔗

  • void set_caret_column(value: int)

  • int get_caret_column()

LineEdit 中游標的列位置。設定後文字可能會滾動以適應它。


bool caret_force_displayed = false 🔗

  • void set_caret_force_displayed(value: bool)

  • bool is_caret_force_displayed()

If true, the LineEdit will always show the caret, even if not editing or focus is lost.


bool caret_mid_grapheme = false 🔗

  • void set_caret_mid_grapheme_enabled(value: bool)

  • bool is_caret_mid_grapheme_enabled()

允許在單個複合字元的元件中進行移動游標、選中、刪除的操作。

注意:倒退鍵 Backspace 始終按複合字元的元件刪除。


bool clear_button_enabled = false 🔗

  • void set_clear_button_enabled(value: bool)

  • bool is_clear_button_enabled()

如果為 trueLineEdit 將在 text 非空時顯示清空按鈕,可以用來快速清除文字。


bool context_menu_enabled = true 🔗

  • void set_context_menu_enabled(value: bool)

  • bool is_context_menu_enabled()

如果為 true,按右鍵將出現本文選單。


bool deselect_on_focus_loss_enabled = true 🔗

  • void set_deselect_on_focus_loss_enabled(value: bool)

  • bool is_deselect_on_focus_loss_enabled()

如果為 true,則在丟失焦點時會取消選中文字。


bool drag_and_drop_selection_enabled = true 🔗

  • void set_drag_and_drop_selection_enabled(value: bool)

  • bool is_drag_and_drop_selection_enabled()

如果為 true,則允許拖放選中的文字。


bool draw_control_chars = false 🔗

  • void set_draw_control_chars(value: bool)

  • bool get_draw_control_chars()

如果為 true,則會顯示控制字元。


bool editable = true 🔗

  • void set_editable(value: bool)

  • bool is_editable()

如果為 false,則不能修改現在的文字,也不能新增新文字。


bool emoji_menu_enabled = true 🔗

  • void set_emoji_menu_enabled(value: bool)

  • bool is_emoji_menu_enabled()

If true, "Emoji and Symbols" menu is enabled.


bool expand_to_text_length = false 🔗

  • void set_expand_to_text_length_enabled(value: bool)

  • bool is_expand_to_text_length_enabled()

如果為 true,則 LineEdit 寬度將增加到比 text 長。如果 text 被縮短,它將壓縮。


bool flat = false 🔗

  • void set_flat(value: bool)

  • bool is_flat()

如果為 true,則 LineEdit 不顯示裝飾。


ExpandMode icon_expand_mode = 0 🔗

Define the scaling behavior of the right_icon.


bool keep_editing_on_text_submit = false 🔗

  • void set_keep_editing_on_text_submit(value: bool)

  • bool is_editing_kept_on_text_submit()

If true, the LineEdit will not exit edit mode when text is submitted by pressing ui_text_submit action (by default: Enter or Kp Enter).


String language = "" 🔗

Language code used for line-breaking and text shaping algorithms. If left empty, the current locale is used instead.


int max_length = 0 🔗

  • void set_max_length(value: int)

  • int get_max_length()

Maximum number of characters that can be entered inside the LineEdit. If 0, there is no limit.

When a limit is defined, characters that would exceed max_length are truncated. This happens both for existing text contents when setting the max length, or for new text inserted in the LineEdit, including pasting.

If any input text is truncated, the text_change_rejected signal is emitted with the truncated substring as a parameter:

text = "Hello world"
max_length = 5
# `text` becomes "Hello".
max_length = 10
text += " goodbye"
# `text` becomes "Hello good".
# `text_change_rejected` is emitted with "bye" as a parameter.

bool middle_mouse_paste_enabled = true 🔗

  • void set_middle_mouse_paste_enabled(value: bool)

  • bool is_middle_mouse_paste_enabled()

如果為 false,將禁用滑鼠中鍵貼上剪貼板。

注意:這個方法只在 Linux 上實作。


String placeholder_text = "" 🔗

  • void set_placeholder(value: String)

  • String get_placeholder()

LineEdit 為空時顯示的文字。它不是 LineEdit 的預設值(見 text)。


Texture2D right_icon 🔗

設定 LineEdit 右端的圖示,這個圖示會在沒有 text 時出現,如果 clear_button_enabledfalse 則始終可見。


float right_icon_scale = 1.0 🔗

  • void set_right_icon_scale(value: float)

  • float get_right_icon_scale()

Scale ratio of the icon when icon_expand_mode is set to EXPAND_MODE_FIT_TO_LINE_EDIT.


bool secret = false 🔗

  • void set_secret(value: bool)

  • bool is_secret()

如果為 true,則每個字元都會被替換成密碼字元(見 secret_character)。


String secret_character = "•" 🔗

  • void set_secret_character(value: String)

  • String get_secret_character()

The character to use to mask secret input. Only a single character can be used as the secret character. If it is longer than one character, only the first one will be used. If it is empty, a space will be used instead.


bool select_all_on_focus = false 🔗

  • void set_select_all_on_focus(value: bool)

  • bool is_select_all_on_focus()

如果為 true,則在獲得焦點時會全選文字。


bool selecting_enabled = true 🔗

  • void set_selecting_enabled(value: bool)

  • bool is_selecting_enabled()

如果為 false,則無法用滑鼠或鍵盤選擇文字。


bool shortcut_keys_enabled = true 🔗

  • void set_shortcut_keys_enabled(value: bool)

  • bool is_shortcut_keys_enabled()

true 時,即使本文選單已被禁用,也會啟用該本文選單的快捷鍵。


StructuredTextParser structured_text_bidi_override = 0 🔗

為結構化文字設定 BiDi 演算法覆蓋。


Array structured_text_bidi_override_options = [] 🔗

  • void set_structured_text_bidi_override_options(value: Array)

  • Array get_structured_text_bidi_override_options()

設定 BiDi 覆蓋的附加選項。


String text = "" 🔗

LineEdit 的字串值。

注意:使用這個屬性更改文字不會觸發 text_changed 訊號。


TextDirection text_direction = 0 🔗

基礎文字書寫方向。


bool virtual_keyboard_enabled = true 🔗

  • void set_virtual_keyboard_enabled(value: bool)

  • bool is_virtual_keyboard_enabled()

If true, the native virtual keyboard is enabled on platforms that support it.


bool virtual_keyboard_show_on_focus = true 🔗

  • void set_virtual_keyboard_show_on_focus(value: bool)

  • bool get_virtual_keyboard_show_on_focus()

If true, the native virtual keyboard is shown on focus events on platforms that support it.


VirtualKeyboardType virtual_keyboard_type = 0 🔗

指定要顯示的虛擬鍵盤的型別。


方法說明

void apply_ime() 🔗

Applies text from the Input Method Editor (IME) and closes the IME if it is open.


void cancel_ime() 🔗

Closes the Input Method Editor (IME) if it is open. Any text in the IME will be lost.


void clear() 🔗

擦除 LineEdittext


void delete_char_at_caret() 🔗

刪除游標目前位置處的一個字元(相當於按 Delete)。


void delete_text(from_column: int, to_column: int) 🔗

刪除 text 中從起始列 from_column 到結束列 to_column 的部分。兩個參數都應該在文字的長度之內。


void deselect() 🔗

清除目前選擇。


void edit(hide_focus: bool = false) 🔗

Allows entering edit mode whether the LineEdit is focused or not. If hide_focus is true, the focused state will not be shown (see Control.grab_focus()).

See also keep_editing_on_text_submit.


PopupMenu get_menu() const 🔗

返回該 LineEditPopupMenu。預設情況下,右鍵點擊 LineEdit 會顯示該菜單。

可以新增自訂功能表專案或移除標準功能表專案。確保你的 ID 不與標準 ID 衝突(請參閱 MenuItems)。例如:

func _ready():
    var menu = get_menu()
    # 在“重做”之後移除所有專案。
    menu.item_count = menu.get_item_index(MENU_REDO) + 1
    # 新增自訂專案。
    menu.add_separator()
    menu.add_item("Insert Date", MENU_MAX + 1)
    # 連接回呼函式。
    menu.id_pressed.connect(_on_item_pressed)

func _on_item_pressed(id):
    if id == MENU_MAX + 1:
        insert_text_at_caret(Time.get_date_string_from_system())

警告:這是一個必需的內部節點,移除和釋放它可能會導致當機。如果希望隱藏它或它的任何子節點,請使用它們的 Window.visible 屬性。


int get_next_composite_character_column(column: int) const 🔗

Returns the correct column at the end of a composite character like ❤️‍🩹 (mending heart; Unicode: U+2764 U+FE0F U+200D U+1FA79) which is comprised of more than one Unicode code point, if the caret is at the start of the composite character. Also returns the correct column with the caret at mid grapheme and for non-composite characters.

Note: To check at caret location use get_next_composite_character_column(get_caret_column())


int get_previous_composite_character_column(column: int) const 🔗

Returns the correct column at the start of a composite character like ❤️‍🩹 (mending heart; Unicode: U+2764 U+FE0F U+200D U+1FA79) which is comprised of more than one Unicode code point, if the caret is at the end of the composite character. Also returns the correct column with the caret at mid grapheme and for non-composite characters.

Note: To check at caret location use get_previous_composite_character_column(get_caret_column())


float get_scroll_offset() const 🔗

返回 caret_column 引起的滾動偏移量,單位為字元數。


String get_selected_text() 🔗

返回選擇內的文字。


int get_selection_from_column() const 🔗

返回選擇的開始列。


int get_selection_to_column() const 🔗

返回選擇結束列。


bool has_ime_text() const 🔗

Returns true if the user has text in the Input Method Editor (IME).


bool has_redo() const 🔗

有“重做”動作可用時返回 true


bool has_selection() const 🔗

如果使用者選中了文字,則返回 true


bool has_undo() const 🔗

有“撤銷”動作可用時返回 true


void insert_text_at_caret(text: String) 🔗

在游標處插入文字 text。如果最終值比 max_length 長,則不會發生任何事情。


bool is_editing() const 🔗

Returns whether the LineEdit is being edited.


bool is_menu_visible() const 🔗

返回選單是否可見。請使用這個方法來代替 get_menu().visible,可以提高性能(因為避免了選單的建立)。


void menu_option(option: int) 🔗

執行 MenuItems 列舉中定義的給定操作。


void select(from: int = 0, to: int = -1) 🔗

選擇 LineEdit 內介於 fromto 之間的字元。預設情況下,from 位於開頭,to 位於結尾。

text = "Welcome"
select() # 將選擇“Welcome”。
select(4) # 將選擇“ome”。
select(2, 5) # 將選擇“lco”。

void select_all() 🔗

選中整個 String


void unedit() 🔗

Allows exiting edit mode while preserving focus.


主題屬性說明

Color caret_color = Color(0.95, 0.95, 0.95, 1) 🔗

LineEdit 的插入符號(文字游標)的顏色。可以設定為完全透明的顏色,從而完全隱藏游標。


Color clear_button_color = Color(0.875, 0.875, 0.875, 1) 🔗

用作清除按鈕預設色調的顏色。


Color clear_button_color_pressed = Color(1, 1, 1, 1) 🔗

按下清除按鈕時使用的顏色。


Color font_color = Color(0.875, 0.875, 0.875, 1) 🔗

預設字形顏色。


Color font_outline_color = Color(0, 0, 0, 1) 🔗

LineEdit 文字輪廓的色調。


Color font_placeholder_color = Color(0.875, 0.875, 0.875, 0.6) 🔗

placeholder_text 的字形顏色。


Color font_selected_color = Color(1, 1, 1, 1) 🔗

選定文字的字形顏色(在選擇矩形內)。


Color font_uneditable_color = Color(0.875, 0.875, 0.875, 0.5) 🔗

禁用編輯時的字形顏色。


Color selection_color = Color(0.5, 0.5, 0.5, 1) 🔗

選擇矩形的顏色。


int caret_width = 1 🔗

文字游標的圖元寬度。使用較大的數值可以提高可存取性,使文字游標更加顯眼,或者確保文字與較大字形尺寸的一致性。


int minimum_character_width = 4 🔗

文字的最小水平空間(不包括清除按鈕和內容邊距)。這個值以“M”字元的數量來衡量(即能夠在不滾動的情況下顯示這麼多個“M”字元)。


int outline_size = 0 🔗

文字輪廓的大小。

注意:如果使用啟用了 FontFile.multichannel_signed_distance_field 的字形,其 FontFile.msdf_pixel_range 必須至少設定為 outline_size兩倍,輪廓算繪才能看起來正確。否則,輪廓可能會比預期的更早被切斷。


Font font 🔗

文字使用的字形。


int font_size 🔗

LineEdit 文字的字形大小。


Texture2D clear 🔗

“清除”按鈕的紋理。見 clear_button_enabled


StyleBox focus 🔗

LineEdit 擁有 GUI 焦點時使用的背景。focus StyleBox 顯示在基礎 StyleBox 之上,所以應該使用部分透明的 StyleBox,確保基礎 StyleBox 仍然可見。代表輪廓或底線的 StyleBox 可以很好地實作這個目的。要禁用聚焦的視覺效果,請指定 StyleBoxEmpty 資源。請注意,禁用聚焦的視覺效果會影響使用鍵盤/手柄進行導覽的可用性,所以出於可存取性的原因,不建議這樣做。


StyleBox normal 🔗

LineEdit 的預設背景。


StyleBox read_only 🔗

LineEdit 處於唯讀模式時使用的背景(editablefalse)。