QSpinBox-How to make it loose focus when I click somewhere outside the QSpinBox.
-
Re: QSpinBox - Clicking outside of the QSpinBox to trigger valueChanged?
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?
Thanks! -
Re: QSpinBox - Clicking outside of the QSpinBox to trigger valueChanged?
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?
Thanks!@Luna
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? -
Re: QSpinBox - Clicking outside of the QSpinBox to trigger valueChanged?
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?
Thanks! -
@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.
Hi
You can set focusPolicy to ClickFocus for your widget.
http://doc.qt.io/qt-5/qwidget.html#focusPolicy-prop
Then QSpinBox will lose focus if clicking on your widget.update: Ah, raven-worx already explained this :)