Checkbox (lv_checkbox)

The Checkbox Widget is created from a "tick box" and a label. When the Checkbox is clicked the tick box is toggled.

Edit on GitHub

Overview

The Checkbox Widget is created from a "tick box" and a label. When the Checkbox is clicked the tick box is toggled.

Parts and Styles

The Checkbox is added to the default group (if one is set).

Usage

Text

The text can be modified with lv_checkbox_set_text(cb, "New text") and will be dynamically allocated.

To set static text, use lv_checkbox_set_text_static(cb, txt). This way, only a pointer to txt will be stored. The provided text buffer must remain available for the lifetime of the Checkbox.

Check, uncheck, disable

You can programmatically check, un-check, and disable the Checkbox by using the common state add/clear function:

 
lv_obj_add_state(cb, LV_STATE_CHECKED);    /* Make Checkbox checked */
lv_obj_remove_state(cb, LV_STATE_CHECKED); /* Make Checkbox unchecked */
lv_obj_add_state(cb, LV_STATE_CHECKED);    /* Make Checkbox checked */
lv_obj_add_state(cb, LV_STATE_DISABLED);   /* Make Checkbox disabled */

To find out whether the Checkbox is checked use lv_obj_has_state(cb, LV_STATE_CHECKED).

Events

Further Reading

Learn more about Events emitted by all Widgets.

Learn more about events.

Keys

The following Keys are processed by Checkbox:

  • LV_KEY_RIGHT/UP Go to CHECKED state if Checkbox is enabled
  • LV_KEY_LEFT/DOWN Go to non-CHECKED state if Checkbox is enabled
  • LV_KEY_ENTER Clicks the Checkbox and toggles its value.

Note that, as usual, the state of LV_KEY_ENTER is translated to LV_EVENT_PRESSED/PRESSING/RELEASED etc.

Further Reading

Learn more about Keys.

Examples

Simple Checkboxes

Checkboxes as radio buttons

API

How is this guide?

Last updated on

On this page