How to change button color just by hovering the mouse cursor?

3 ビュー (過去 30 日間)
Israel  Hernández
Israel Hernández 2019 年 8 月 2 日
回答済み: awezmm 2019 年 8 月 3 日
How can I change the color of a button without clicking it, just by hovering the mouse cursor over it, change the color and return to its state when it is outside the button area.

回答 (1 件)

awezmm
awezmm 2019 年 8 月 3 日
You can continuosly track the position of the cursor inside the figure window.
When the coordinates of the curor are in the coordinates of the the button you can change the color
To continuosly read the position of the mouse, first assign a callback function:
set (gcf, 'WindowButtonMotionFcn', @mouseMove);
Next, create the callback function:
function mouseMove (object, eventdata)
C = get (gca, 'CurrentPoint');
title(gca, ['(X,Y) = (', num2str(C(1,1)), ', ',num2str(C(1,2)), ')']);
Now in this mouseMove function you should have some sort of if state that tests if the cursor is moved into the button and if it is reference the button BackgroundColor propery to change it.
Perhaps also reset the color to default when the user has moved their cursor outside.
Ref link: track-mouse

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by