Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QSpinBox-How to make it loose focus when I click somewhere outside the QSpinBox.
Luna last edited by aha_1980
I'd like my QSpinBox to loose focus and trigger valueChanged when the user click somewhere outside the QSpinBox.
This is usually the normal way to handle focus, so I don't understand why it's not using this way as default with QSpinBox.
Now the focus is only lost when I click on another button, or another QSpinBox, but not when clicking my QWidget.
Is there a way to force this behavior?
this is a question of your widget hierarchy.
When you click outside your widget the click event will be propagated to the next possible widget. If a widget is found which accepts focus on mouse clicks the focus is transferred which will lead to an focus-out event on your spinbox.
You may want to try to set the focus policy (make it accept focus) on your window / root-widget.
Did you set any special focus related stuff on other widgets in your application?
@Luna This is normal behaviour: you need to click on other widget which accepts focus, if you click on some empty space in your app the focus will stay where it is.
You can set focusPolicy to ClickFocus for your widget.
Then QSpinBox will lose focus if clicking on your widget.
update: Ah, raven-worx already explained this :)