How to create a model dialog with lvgl?


How to create a model dialog with lvgl?

When I was using lvgl, I found it a little difficult to create a modal dialog window.

Hi @zhwxChaos,

Please see this post.

Kind Regards,


I’m doing this now, but I find that it’s a bit difficult if another modal dialog pops up on the modal dialog.

lv_obj_t * m = lv_msgbox_create(lv_layer_top(), NULL);

It should work as long as you create the second one after the first one. Can you explain in more detail what the issue is, please?

for example,
1、click one button to modify some parameters. Then I pop up one modal dialog.
2、before saving parameters,check them. if some err ,then I need a messagebox to tell user.

This is a very common scenario!

In addition, I hope that after the messagebox pops up, it waits for the user to make a choice before executing the following logic.
Not the way it is now…

That’s not directly possible with an event-driven architecture. You would need to register an event handler for the choices and run your logic inside that instead of where you create the message box. Admittedly, it’s a bit cumbersome, but this is how both the web and LVGL work, and it gives the most flexibility while avoiding issues like recursion.

In that case, I think you could still create a second modal background and message box, and I don’t see why it would appear behind the previous one. Can you provide a simple code snippet that demonstrates the problem?