Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

my problem is with combining EventHandler and MouseAppearance. I want to change cursor appearance if I have primary button pressed over on item. But only then, after releasing it should be "Arrow" back.

I thought it should work:

Dynamic@MouseAppearance[#, mysz]&@EventHandler[
  Framed["A"], {"MouseUp" :> (mysz = "Arrow"), "MouseDown" :> (mysz = "A")}]

but it doesn't. The strange thing is, using "MouseClicked" it works, of course effect is different, it works like it should. Second thing is variable "mysz" is updated to "A" while button is pressed... but appearance doesn't change.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I couldn't get the mouse to change appearance while being pressed, so I think you'll need a work-around. What I would suggest is to simulate the mouse with a graphics Inset that looks like an arrow and follows the mouse, while making the actual mouse cursor invisible for the entire time the mouse is inside the object.

This works only if the object is changed from your simple Framed to a Graphics object, and the code is certainly a bit more complicated that I would have liked:

DynamicModule[{
  mysz,
  mouse = 
   Graphics[{Arrowheads[1.4], Arrow[{{0, 0}, {-.5, 1}}]}, 
    ImageSize -> 8], n},
 mysz = mouse;
 Dynamic[MouseAppearance[#, " "] &@EventHandler[
    Graphics[{Orange, Rectangle[{0, 0}, {1, 1}], Black, Inset["A"], 
      Inset[mysz, MousePosition["Graphics", {-1, -1}]]}, 
     ImageSize -> 30, PlotRange -> {{0, 1}, {0, 1}}],
    {"MouseUp" :> (mysz = mouse),
     "MouseDown" :> (mysz = "A";)}]
  ]
 ]

The EvenetHandler logic is essentially the same as what you had already, but instead of mysz determining the appearance of the mouse, it sets the Inset that follows the MousePosition. This seems to work fine in principle, except for a new glitch that sometimes happens when the mouse position isn't correctly tracked as you enter the Graphics from the bottom. I just asked a separate question about this, and it could be that it's localized to version 9 of Mathematica and Mac OS X.

But apart from that, when I press the mouse it causes the simulated cursor to change to A immediately, and the A can also follow while dragging.

share|improve this answer
    
Yes, Your way works. But it won't help me. General idea is to have many items with this function on the field, those items will differ with size, position and mousegraphic. I had similar to Yours solution earlier but it is not convinient to use standard positioning. I want to set things buy Grid or sth. Thats why I left Graphics way. –  Kuba Jan 21 '13 at 10:41
    
But what is even more important than the solution is WHY it does not work? :) In my opinion it should, something is wrong with MouseAppearance :/ –  Kuba Jan 21 '13 at 16:14
    
Sorry it won't work for you, but I don't have any better insight into the mouse appearance while it's being pressed. I tried using the drag event instead, but that didn't work either (for mouse appearance). –  Jens Jan 21 '13 at 17:06
    
Don't be sorry :) thank You for Your time. –  Kuba Jan 21 '13 at 17:44
    
I decided to accept your answer finally because even though it is a workaround I couldn't find better then mine previous and I believe yours will be useful for future visitors. –  Kuba Sep 11 '13 at 7:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.