Prevents mouse clicks from penetrating the Rectangle

how to Prevents mouse clicks from penetrating the Rectangle in the zstack?

self._window = ui.Window("My Window", width=300, height=300)
        with self._window.frame:
            with ui.ZStack():

                with ui.VStack():
                    label = ui.Label("")

                    def on_click():
                        self._count += 1
                        label.text = f"count: {self._count}"

                    def on_reset():
                        self._count = 0
                        label.text = "empty"

                    on_reset()

                    with ui.HStack():
                        ui.Button("Add", clicked_fn=on_click)
                        ui.Button("Reset", clicked_fn=on_reset)

                ui.Rectangle(width=80, style={"background_color": 0x220000FF})


5b633b1361fd6edef75d73438d86f5a

the red Rectangle pannel is on the button with zstack, when the mouse hovered on the red rectangle,how to prevent mouse press event

You can prevent the click on the button by putting teh rectangle in a container that has content_clipping=True

import omni.ui as ui
window = ui.Window("My Window", width=300, height=300)
with window.frame:
    with ui.ZStack():
        with ui.VStack():
            label = ui.Label("")

            def on_click():
                print("Hello")

            def on_reset():
                print("empty")

            with ui.HStack():
                ui.Button("Add", clicked_fn=on_click)
                ui.Button("Reset", clicked_fn=on_reset)

        with ui.VStack(content_clipping=True):
            ui.Rectangle(width=80)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.