Forward focus to the contentItem of editable spinboxes
This fixes the scenario where a SpinBox is shown for the first time with focus, but its editor (TextInput) doesn't have active focus. tst_focus' keyNavigation.qml had to be adjusted, as an editable spinbox will now consume key events. Task-number: QTBUG-60356 Change-Id: I3af0260a22e9633ab6110d6adab7b39a22b849de Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
This commit is contained in:
parent
743d0132fe
commit
039c25daac
|
@ -719,6 +719,16 @@ void QQuickSpinBox::decrease()
|
|||
setValue(d->value - d->effectiveStepSize());
|
||||
}
|
||||
|
||||
void QQuickSpinBox::focusInEvent(QFocusEvent *event)
|
||||
{
|
||||
Q_D(QQuickSpinBox);
|
||||
QQuickControl::focusInEvent(event);
|
||||
|
||||
// When an editable SpinBox gets focus, it must pass on the focus to its editor.
|
||||
if (d->editable && d->contentItem && !d->contentItem->hasActiveFocus())
|
||||
d->contentItem->forceActiveFocus(event->reason());
|
||||
}
|
||||
|
||||
void QQuickSpinBox::hoverEnterEvent(QHoverEvent *event)
|
||||
{
|
||||
Q_D(QQuickSpinBox);
|
||||
|
|
|
@ -127,6 +127,7 @@ Q_SIGNALS:
|
|||
Q_REVISION(2) void inputMethodComposingChanged();
|
||||
|
||||
protected:
|
||||
void focusInEvent(QFocusEvent *event) override;
|
||||
void hoverEnterEvent(QHoverEvent *event) override;
|
||||
void hoverMoveEvent(QHoverEvent *event) override;
|
||||
void hoverLeaveEvent(QHoverEvent *event) override;
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
import QtQuick 2.2
|
||||
import QtTest 1.0
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Window 2.3
|
||||
|
||||
TestCase {
|
||||
id: testCase
|
||||
|
@ -422,6 +423,16 @@ TestCase {
|
|||
compare(control.value, 100)
|
||||
}
|
||||
|
||||
function test_initialFocus() {
|
||||
var window = testCase.Window.window
|
||||
verify(window)
|
||||
compare(window.activeFocusItem, window.contentItem)
|
||||
|
||||
var control = createTemporaryObject(spinBox, testCase, { editable: true, focus: true })
|
||||
verify(control)
|
||||
tryCompare(control.contentItem, "activeFocus", true)
|
||||
}
|
||||
|
||||
function test_editable() {
|
||||
var control = createTemporaryObject(spinBox, testCase)
|
||||
verify(control)
|
||||
|
|
|
@ -191,7 +191,6 @@ Item {
|
|||
SpinBox {
|
||||
id: spinbox
|
||||
objectName: "spinbox"
|
||||
editable: true
|
||||
value: 50
|
||||
KeyNavigation.left: radiobutton2
|
||||
KeyNavigation.right: swtich
|
||||
|
|
Loading…
Reference in New Issue