QR Code (lv_qrcode)
Generates and displays a QR-code bitmap from a string.
Overview
The QR Code widget generates and displays a QR-code bitmap from a string using LVGL's QR-code library. Its size, colors and the encoded text are configurable.
Learn more in the LVGL Open documentation.
/**
* @file lv_example_qrcode.c
*/
#include "../lv_examples.h"
/**
* @title QR code
* @brief Two QR codes with custom colours, size and quiet zone.
*
* `data` is the encoded UTF-8 string and `size` sets the square side in
* pixels. `dark_color`/`light_color` recolour the modules and background,
* and `quiet_zone="true"` adds the recommended margin so scanners read it
* reliably.
*/
void lv_example_qrcode(void)
{
lv_obj_t * screen = lv_screen_active();
lv_obj_t * lv_qrcode_0 = lv_qrcode_create(screen);
lv_qrcode_set_size(lv_qrcode_0, 120);
lv_obj_set_align(lv_qrcode_0, LV_ALIGN_CENTER);
lv_obj_set_x(lv_qrcode_0, -100);
lv_qrcode_set_dark_color(lv_qrcode_0, lv_color_hex(0x1f2937));
lv_qrcode_set_light_color(lv_qrcode_0, lv_color_hex(0xffffff));
lv_qrcode_set_quiet_zone(lv_qrcode_0, true);
lv_qrcode_set_data(lv_qrcode_0, "https://lvgl.io");
lv_obj_t * lv_qrcode_1 = lv_qrcode_create(screen);
lv_qrcode_set_size(lv_qrcode_1, 100);
lv_obj_set_align(lv_qrcode_1, LV_ALIGN_CENTER);
lv_obj_set_x(lv_qrcode_1, 100);
lv_qrcode_set_dark_color(lv_qrcode_1, lv_color_hex(0x2563eb));
lv_qrcode_set_light_color(lv_qrcode_1, lv_color_hex(0xeff6ff));
lv_qrcode_set_quiet_zone(lv_qrcode_1, true);
lv_qrcode_set_data(lv_qrcode_1, "https://lvgl.io");
}
<!--
@title QR code
@brief Two QR codes with custom colours, size and quiet zone.
`data` is the encoded UTF-8 string and `size` sets the square side in
pixels. `dark_color`/`light_color` recolour the modules and background,
and `quiet_zone="true"` adds the recommended margin so scanners read it
reliably.
-->
<screen>
<view>
<lv_qrcode
size="120"
align="center"
x="-100"
dark_color="0x1f2937"
light_color="0xffffff"
quiet_zone="true"
data="https://lvgl.io"
/>
<lv_qrcode
size="100"
align="center"
x="100"
dark_color="0x2563eb"
light_color="0xeff6ff"
quiet_zone="true"
data="https://lvgl.io"
/>
</view>
</screen>
Properties
Parts
Style parts of the widget with local style (e.g. style_bg_color-knob="0xff0000") or with style sheets (e.g. <style name="style_knob" selector="knob">). See Styles to learn more.
| Part | Description |
|---|---|
main | Style the area behind the QR code: background, border and padding. The module colors come from dark_color/light_color, not from style properties. |
Properties below are the widget's XML <api>; see API for how properties, parameters and elements work.
| Property | Type | Description |
|---|---|---|
size | int | Set the QR code size in pixels (instead of width/height) |
dark_color | color | Set the foreground color |
light_color | color | Set the background color |
data | string | Set the encoded UTF-8 data |
quiet_zone | bool | Add margin around the QR code |
Last updated on