How to reuse widgets on different screens

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the FAQ and read the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.


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


What LVGL version are you using?


What do you want to achieve?

I want to call and use the widget on the 1st screen in the same way on the 2nd screen.

What have you tried so far?

I looked up whether there is a widget init function in documents.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

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.

If you have moved to another screen and there is a specific way to call a widget, please let us know.

“call and use the widget on the 1st screen in the same way on the 2nd screen”
In the same way or actually use the same object?
There’s a lv_obj_set_parent(obj, new_parent).
Never tried but I’d say it should cover the second case.
Otherwise it simply sounds like a function that creates the object the way you want.


1 Like

We are going to use the same object on the 1st and 2nd screens.
Let’s try it.
thank you

I have exactly the same use case. Unfortunately set_parent function is not working as expected. The object is not appearing. Could you successfully move the object?