I have a small “bug” in one of my porgram that I can’t find a simple solution.
I have an image button with both normal image and an overImage.
When the mouse enter the button, the overImage is displayed. Then if the user clicks the button, my program needs to hide the button and reset the position of the mouse to the center of the screen;
A few seconds later I make the button visible again (the mouse was still at the screen center I.e. not over the button). But the button still shows the “overImage” instead of normal Image. then if the mouse is moved by the user, the button returns to the normal image.
I suspect a problem with the mouseexit not been called.
CenterMouse(); // move louse to screencenter (outside button)
Rep1Button->setState(Rep1Button->buttonNormal ); //tried this but didn't worl
Rep1Button->repaint(); //tried this but didn't work
Rep1Button->setVisible(false);
When I do a Rep1Button->setVisible(true); the overImage is displayed until user move mouse.
How to avoid this ?
at the begining of th eprogram the button is diplayed
When the user click on the button (and since the mouse entered the button area overImage was displayed) I call toggleResponseButtons(false)
and 5 seconds later (triggered with a Timer) I made a new call to toggleResponseButtons(true) to make the button visible again but with overImage displayed until the user moves the mouse.
The experiment : I did comment the last line of my toggleResponseButtons button as below :
void myclass::toggleResponseButtons(bool state)
{
CenterMouse();
Rep1Button->setState(Rep1Button->buttonNormal );Rep1Button->repaint();
//Rep1Button->setVisible(state); <Do not change visibility of the button
}
That was the only change in my program. At the 1st call to toggleResponseButtons(false) the button did not disappeared (of course) but it went back to the normalImage immediately.
Thus it seems that the setVisible(false) prevent the button from going back to the normalImage.
When you make it invisible, Button::visibilityChanged gets called, which automatically updates the state based on the mouse, so there’s no point setting the state explicitly yourself beforehand. Try calling setState after making it invisible, and you might have more luck!
When you click on the second button (Image only drawable button) it will diseappear and the position of the mous will change. Just wait 3s and the button will reappear but with the “overImage” despite the fact thet the mouse is not over the button.
Ok… Before I try it, does this only happen if you keep the mouse completely still? Because Desktop::setMousePosition will not generate any mouse-move events (all OSes work that way: they just move the visible cursor, and never act as if the user moved it), so until you actually move the mouse, you can’t really expect anything to get updated.
does this only happen if you keep the mouse completely still?
Yes. if the user moves the mouse after the mouse center, the button goes to “normalImage”.
that is probably the good explanation except that it is then strange to observe the expected behavior in my modified example where I bypass the seVisible(false). Even with no user-initiated mouse movements, the button returns to the normalImage.
void myclass::toggleResponseButtons(bool state)
{
CenterMouse();
Rep1Button->setState(Rep1Button->buttonNormal );Rep1Button->repaint();
//Rep1Button->setVisible(state); <Do not change visibility of the button
}
Anyway, is there any mean to force the update or if it is possible to simulate a user mouse movement ?
Until the mouse moves, the app will still see it at its old position inside the button, so I think everything is behaving perfectly “correctly”. AFAIK there’s no way to force a mouse-move via the OS (OSes make that difficult, probably for security reasons).
And guess what ? It works. Not the ideal situation for me since the buttons are still slightly visible (the software is targeted at aged people) but I think I can deal with it…
Remark : if I add “Rep1Button->setVisible(state);” at the end of the method (after the seEnabled) then The problem reappears… The execution of setVisible seems to block the update of the button status. Quite strange. One alternative solution may be to wait a little before the set visible…