How to make a control can be dragged and thrown

Description

How to make a control can be dragged and thrown

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

QT create

What LVGL version are you using?

V9.0.0

What do you want to achieve?

try add flag and set obj style,but not find function

What have you tried so far?

Code to reproduce

rect_1 = lv_obj_create(parent);
lv_obj_set_size(rect_1,150,150);
lv_obj_set_style_bg_color(rect_1,lv_palette_main(LV_PALETTE_BLUE),0);
lv_obj_add_flag(rect_1,LV_OBJ_FLAG_IGNORE_LAYOUT);

The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

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

I tried to disable gesture and event propagation to the parent, but it didn’t work properly

lv_obj_t * rect_1,* rect_2;

static void drag_event_handler(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);

lv_indev_t * indev = lv_indev_active();
if(indev == NULL)  return;

lv_point_t vect;
lv_indev_get_vect(indev, &vect);

int32_t x = lv_obj_get_x_aligned(obj) + vect.x;
int32_t y = lv_obj_get_y_aligned(obj) + vect.y;
lv_obj_set_pos(obj, x, y);

}

static void bagua_create(lv_obj_t * parent)
{
rect_1 = lv_obj_create(parent);
lv_obj_set_size(rect_1,150,150);
lv_obj_set_style_bg_color(rect_1,lv_palette_main(LV_PALETTE_BLUE),0);
lv_obj_add_flag(rect_1,LV_OBJ_FLAG_IGNORE_LAYOUT);
lv_obj_remove_flag(rect_1,LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_remove_flag(rect_1,LV_OBJ_FLAG_GESTURE_BUBBLE);

rect_2 = lv_obj_create(parent);
lv_obj_set_size(rect_2,150,150);
lv_obj_set_style_bg_color(rect_2,lv_palette_main(LV_PALETTE_RED),0);
lv_obj_add_flag(rect_2,LV_OBJ_FLAG_IGNORE_LAYOUT);
lv_obj_remove_flag(rect_2,LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_remove_flag(rect_2,LV_OBJ_FLAG_GESTURE_BUBBLE);

lv_obj_align_to(rect_2,rect_1,LV_ALIGN_OUT_RIGHT_MID,0,0);

lv_obj_add_event_cb(rect_1,drag_event_handler, LV_EVENT_PRESSING, NULL);
lv_obj_add_event_cb(rect_2,drag_event_handler, LV_EVENT_PRESSING, NULL);

}

录制_2024_03_16_16_40_50_397.zip (1.3 MB)