Why the push_button always keeps the state of mouse hovering?
-
I comed across the problem in my own open source project.
The project is about algorithm visulization.
Just as above image shows, when I click the "Start" push-button in the bottom-right of the image, the push-button will show two different states.
- When I click "start" and hover the mouse over the push_button a period of time, the push-button will keep the state of mouse hovering, you can see it in the below .gif images.
- When I click "start" and let the mouse leave it immediately., the push-button will back to normal state, you can see it in the below .gif images.
And I don't change the push-buton stylesheet, Not change any stylesheet!
My project is located in https://github.com/Hapoa/Visual-Algorithms.
Because the files are a little much, so you just need to focus on the "start()" function in the "display/d_bfs.cpp" file. When click the "start" push-button, the "start()" function will run.
-
I comed across the problem in my own open source project.
The project is about algorithm visulization.
Just as above image shows, when I click the "Start" push-button in the bottom-right of the image, the push-button will show two different states.
- When I click "start" and hover the mouse over the push_button a period of time, the push-button will keep the state of mouse hovering, you can see it in the below .gif images.
- When I click "start" and let the mouse leave it immediately., the push-button will back to normal state, you can see it in the below .gif images.
And I don't change the push-buton stylesheet, Not change any stylesheet!
My project is located in https://github.com/Hapoa/Visual-Algorithms.
Because the files are a little much, so you just need to focus on the "start()" function in the "display/d_bfs.cpp" file. When click the "start" push-button, the "start()" function will run.
@Limer said in Why the push_button always keeps the state of mouse hovering?:
Because the files are a little much, so you just need to focus on the "start()" function in the "config/d_bfs.cpp" file.
there is no such file and function.
-
@Limer said in Why the push_button always keeps the state of mouse hovering?:
Because the files are a little much, so you just need to focus on the "start()" function in the "config/d_bfs.cpp" file.
there is no such file and function.
@raven-worx Sorry, the path is wrong.
It is located in "display/d_bfs.cpp"
-
@raven-worx Sorry, the path is wrong.
It is located in "display/d_bfs.cpp"
@Limer
This happens because you disable the start button (and therefore the mouse leave event): by disabling the button before leaving it, you lock-in the hover state.void SearchBase::start() { startPushButton->setEnabled(false); ... emit startSignal(); }
You can avoid this by first changing the
WA_UnderMouse
attribute (as found from this post)startPushButton->setAttribute(Qt::WA_UnderMouse, false); startPushButton->setEnabled(false);
-
@Limer
This happens because you disable the start button (and therefore the mouse leave event): by disabling the button before leaving it, you lock-in the hover state.void SearchBase::start() { startPushButton->setEnabled(false); ... emit startSignal(); }
You can avoid this by first changing the
WA_UnderMouse
attribute (as found from this post)startPushButton->setAttribute(Qt::WA_UnderMouse, false); startPushButton->setEnabled(false);
@Diracsbracket Thank you very much. 'setAttribute()' is a perfect solution.
-
@Diracsbracket Thank you very much. 'setAttribute()' is a perfect solution.
@Limer
Hi. Don't forget to mark this question as solved! -
@Limer
Hi. Don't forget to mark this question as solved!If so, should I always add "setAttribute(Qt::WA_UnderMouse, false)" before "PushButton->setEnabled(false)"?
Or we only need to add it in some special scenes?
-
If so, should I always add "setAttribute(Qt::WA_UnderMouse, false)" before "PushButton->setEnabled(false)"?
Or we only need to add it in some special scenes?
@Limer
Disabling the button or any widget for that matter means you disable the events for it, so... If you don't want the same format locking-in as you had before, then I guess you must use it with all the other buttons as well, or maybe you could disable hovering altogether. -
@Limer
Disabling the button or any widget for that matter means you disable the events for it, so... If you don't want the same format locking-in as you had before, then I guess you must use it with all the other buttons as well, or maybe you could disable hovering altogether.@Diracsbracket Ok, thank you for your warm responses.