# Create a SWITCH event that enables other widget

**URL:** <http://forum.squareline.io/t/create-a-switch-event-that-enables-other-widget/277>\
**Category:** How to\
**Created:** [May 13, 2022, 12:16pm UTC](http://forum.squareline.io/t/create-a-switch-event-that-enables-other-widget/277 "2022-05-13T12:16:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndyFraser](http://forum.squareline.io/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@AndyFraser](http://forum.squareline.io/u/AndyFraser)\
**Post date:** [May 13, 2022, 12:16pm UTC](http://forum.squareline.io/t/create-a-switch-event-that-enables-other-widget/277/1 "2022-05-13T12:16:38Z")

</div>

### What do you want to achieve?

I have a Switch widget and I would like to add a state or states to change the Disabled state of another widget. So when the switch is ON, I would like to disable an Image Button and when the switch is OFF I would like to enable an Image Button.

I could write this in code but it would be nicer for SLS to hookup the ability automatically for me.

### What have you tried so far?

I created two events one for CHECKED which adds a DISABLED state to the Image Button and one for UNCHECKED which removes a DISABLED state. However, it seems that SWITCH does not generate a checked/unchecked event.

### Screenshot or video

 ![SWITCH Events](http://forum.squareline.io/uploads/default/original/1X/19740a89f7f0a678faedfbbd255eec03d89ecb66.png)

### Others

- **SquareLine Studio version:**  
1.0.5
- **Operating system:**  
Windows 10 x64
- **Target hardware:**  
Raspberry Pi 4.

---

<div class="post-metadata">

**Author:** ![dronecz](http://forum.squareline.io/letter_avatar_proxy/v4/letter/d/49beb7/32.png) [@dronecz](http://forum.squareline.io/u/dronecz)\
**Post date:** [May 15, 2022, 9:24pm UTC](http://forum.squareline.io/t/create-a-switch-event-that-enables-other-widget/277/2 "2022-05-15T21:24:06Z")

</div>

What about removing “Clickable” flag from that Image Button when switch is ON and add it when swith is OFF? Will that do what you need?

---

<div class="post-metadata">

**Author:** ![kisvegabor](http://forum.squareline.io/user_avatar/forum.squareline.io/kisvegabor/32/537_2.png) [@kisvegabor](http://forum.squareline.io/u/kisvegabor)\
**Post date:** [May 16, 2022, 7:06am UTC](http://forum.squareline.io/t/create-a-switch-event-that-enables-other-widget/277/3 "2022-05-16T07:06:40Z")

</div>

I think the problem is with the image button and LVGL. In LVGL the image button’s state should be changed with `lv_imgbtn_set_state` instead of the generic `lv_obj_add/clear_state()`. Can you try if it works with a normal `lv_btn`?

---

<div class="post-metadata">

**Author:** ![AndyFraser](http://forum.squareline.io/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@AndyFraser](http://forum.squareline.io/u/AndyFraser)\
**Post date:** [May 16, 2022, 8:03am UTC](http://forum.squareline.io/t/create-a-switch-event-that-enables-other-widget/277/4 "2022-05-16T08:03:56Z")

</div>

Yes, it seems to work fine with a normal button.

Andy

---

<div class="post-metadata">

**Author:** ![kisvegabor](http://forum.squareline.io/user_avatar/forum.squareline.io/kisvegabor/32/537_2.png) [@kisvegabor](http://forum.squareline.io/u/kisvegabor)\
**Post date:** [May 17, 2022, 9:34am UTC](http://forum.squareline.io/t/create-a-switch-event-that-enables-other-widget/277/5 "2022-05-17T09:34:28Z")

</div>

Thanks.  
I need to address it in LVGL. ☹
