Links

MouseRegion

The MouseRegion widget lets you know whenever the mouse pointer enters or exits from a widget. You could use it to build a user experience (UX), such as animating buttons when a user hovers over them and revealing or hiding menu items when a user hovers over the menu icon.
On this page, you will learn how to add the MouseRegion widget, use it to show/hide elements, and customize it.
MouseRegion widget

Adding MouseRegion widget

Let's build an example that animates the button when hovered over it. Here's how it looks:
Animating button when hovered over it
Here are the step-by-step instructions to build such an example:
  • First, click on the + Add Widget and drag the MouseRegion widget from the Base Elements tab or add it directly from the widget tree.
  • Add a Button (inside MouseRegion) with On Action Trigger animation.
  • Select the MouseRegion widget, select Actions from the Properties panel (the right menu), and click Open. This will open an Action flow Editor in a new popup window.
  • Select the On Mouse Enter tab. Actions added under this will be triggered whenever the mouse enters the MouseRegion widget.
  • Select the On Mouse Exit tab. Actions added under this will be triggered whenever the mouse leaves the MouseRegion widget.
Adding a mouse region widget to animate a button

Show/hide elements using MouseRegion

Using the callbacks provided by the MouseRgion widget, you can show or hide a widget. The idea is to update the Local State variable when the mouse pointer enters or exits the widget. And then, use the same local state variable to add Conditional Visibility on a widget.
Let's see how to build the following example:
Show/hide menu items
Here are the step-by-step instructions:
  • First, add the Stack > Container > MouseRegion > IconButton to display the menu icon.
  • Add the Container > MouseRegion > Column (with some menu items/options) inside the same Stack widget.
Note that we wrapped the menu icon and its options inside the MouseRegion widget. In the next step, we will add the same actions for both MouseRegion widgets so that the menu options stay visible as long as you hover over them.
Adding a menu icon and its options
Use local state variable and MouseRegion to show/hide a widget

Customizing

You can customize the appearance and behavior of this widget using the various properties available under the properties panel.

Customize mouse cursor

When a mouse enters the widget, its cursor will change to the appropriate one by default. However, you can also set it to a custom one if you wish to.
To customize the mouse cursor, select the MouseRegion widget, move to the properties panel, find the Mouse Cursor dropdown select the one you think fits best.
Customize mouse cursor

Add padding

​Here are the instructions on how to add padding.

Adjust alignment

​Here are the instructions for adjusting the alignment.
Last modified 6mo ago