Up to date

This page is up to date for Godot 4.3. If you still find outdated information, please open an issue.

SpinBox

Inherits: Range < Control < CanvasItem < Node < Object

An input field for numbers.

Description

SpinBox is a numerical input text field. It allows entering integers and floating-point numbers.

Example:

var spin_box = SpinBox.new()
add_child(spin_box)
var line_edit = spin_box.get_line_edit()
line_edit.context_menu_enabled = false
spin_box.horizontal_alignment = LineEdit.HORIZONTAL_ALIGNMENT_RIGHT

The above code will create a SpinBox, disable context menu on it and set the text alignment to right.

See Range class for more options over the SpinBox.

Note: With the SpinBox's context menu disabled, you can right-click the bottom half of the spinbox to set the value to its minimum, while right-clicking the top half sets the value to its maximum.

Note: SpinBox relies on an underlying LineEdit node. To theme a SpinBox's background, add theme items for LineEdit and customize them.

Note: If you want to implement drag and drop for the underlying LineEdit, you can use Control.set_drag_forwarding on the node returned by get_line_edit.

Properties

HorizontalAlignment

alignment

0

float

custom_arrow_step

0.0

bool

editable

true

String

prefix

""

bool

select_all_on_focus

false

BitField[SizeFlags]

size_flags_vertical

1 (overrides Control)

float

step

1.0 (overrides Range)

String

suffix

""

bool

update_on_text_changed

false

Methods

void

apply()

LineEdit

get_line_edit()

Theme Properties

Texture2D

updown


Property Descriptions

HorizontalAlignment alignment = 0 🔗

Changes the alignment of the underlying LineEdit.


float custom_arrow_step = 0.0 🔗

  • void set_custom_arrow_step(value: float)

  • float get_custom_arrow_step()

If not 0, Range.value will always be rounded to a multiple of custom_arrow_step when interacting with the arrow buttons of the SpinBox.


bool editable = true 🔗

  • void set_editable(value: bool)

  • bool is_editable()

If true, the SpinBox will be editable. Otherwise, it will be read only.


String prefix = "" 🔗

Adds the specified prefix string before the numerical value of the SpinBox.


bool select_all_on_focus = false 🔗

  • void set_select_all_on_focus(value: bool)

  • bool is_select_all_on_focus()

If true, the SpinBox will select the whole text when the LineEdit gains focus. Clicking the up and down arrows won't trigger this behavior.


String suffix = "" 🔗

Adds the specified suffix string after the numerical value of the SpinBox.


bool update_on_text_changed = false 🔗

  • void set_update_on_text_changed(value: bool)

  • bool get_update_on_text_changed()

Sets the value of the Range for this SpinBox when the LineEdit text is changed instead of submitted. See LineEdit.text_changed and LineEdit.text_submitted.


Method Descriptions

void apply() 🔗

Applies the current value of this SpinBox.


LineEdit get_line_edit() 🔗

Returns the LineEdit instance from this SpinBox. You can use it to access properties and methods of LineEdit.

Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their CanvasItem.visible property.


Theme Property Descriptions

Texture2D updown 🔗

Sets a custom Texture2D for up and down arrows of the SpinBox.