LV_Table how to set padding for nth row?


I have a table where I have font size 24 for the header and 18 for the rows.
How can I set the padding for the 1+ rows?

What MCU/Processor/Board and compiler are you using?

Simulator and Linux

What LVGL version are you using?


What do you want to achieve?

As description

What have you tried so far?

Ive not found much I can use

Code to reproduce

    info.batterytable = lv_table_create(parent);
    lv_obj_set_style_bg_color(info.batterytable, lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN);
    lv_obj_set_style_bg_color(info.batterytable, lv_color_hex(MAIN_BG_COLOUR), LV_PART_ITEMS);
    lv_obj_set_style_border_color(info.batterytable, MAIN_BORDER_COLOUR, LV_PART_MAIN);
    lv_obj_set_style_border_color(info.batterytable, MAIN_BORDER_COLOUR, LV_PART_ITEMS);

    lv_obj_set_style_radius(info.batterytable, 10, 0);
    lv_obj_set_style_clip_corner(info.batterytable, true, 0);

    /*right then down*/
    lv_obj_align_to(info.batterytable, btn_randomFactUpdate, LV_ALIGN_OUT_BOTTOM_LEFT, 10, 40);

    lv_obj_set_style_pad_top(info.batterytable, 4, LV_PART_ITEMS);
    lv_obj_set_style_pad_bottom(info.batterytable, -4, LV_PART_ITEMS);

    lv_table_set_col_cnt(info.batterytable, 2);

static void draw_part_batterytable_event_cb(lv_event_t * e)
    lv_obj_t * obj = lv_event_get_target(e);
    lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e);
    /*If the cells are drawn...*/
    if(dsc->part == LV_PART_ITEMS) {
        uint32_t row = dsc->id /  lv_table_get_col_cnt(obj);
        dsc->rect_dsc->bg_color = lv_color_hex(MAIN_BG_COLOUR);

        if(row > 0) {
            dsc->label_dsc->font = &lv_font_montserrat_18;
            //dsc->label_dsc->pad_bottom = -8;

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Thanks all

lv_obj_set_style_text_font(obj, &lv_font_montserrat_18, LV_PART_ITEMS);

inside the draw instead of your line:

dsc->label_dsc->font = &lv_font_montserrat_18;

I think you will find that will set the font… having said that, you may have to play with the individual cell heights in order to get something that looks clean.

Hi @JMellen,

While that sort of works it also sets the header row to font size 18. I’d like to do it for only the row 1+.

Any other ideas?


Nope. I ran into several roadblocks myself with this and ended up making labels above the table for the header, then using the table below. You can make them buttons instead if you want to enable sorting etc and you can format them any way you like. If you want to be able to move the assembly around, then place all of the objects inside a normal object (instead of the lv_scr_act) and then you can move or hide that object and the entire thing becomes it’s own “control”. It worked out (maybe even a little better) for me that way. I hope it works out for you too.