QML TextInput:如何检测焦点事件?
QML TextInput: how detect focus out event?
我需要 https://doc.qt.io/qt-5/qml-qtquick-textinput.html#editingFinished-signal 的模拟。
因此,当用户按下 enter/space 时,将焦点更改为我需要信号的另一个项目。
问题是 editingFinished 对我没用。它仅在以下情况下有效
没有 mask/validator,在其他情况下如果 TextInput
是 invalid/incomplete 状态,
没有编辑完成信号。所以我想要它仿真。
我无法在 C++ 中继承 QQuickTextInput
,因为它是私有的 class。
我可以在 QML 中继承 TextInput
,但是如何在 QML class 中获取 focusOutEvent
继承 TextInput
?
您可以在 activeFocus
属性 上使用来检查对象是否具有焦点。
TextInput {
onActiveFocusChanged: {
if (activeFocus) {
// Gained focus
} else {
// Lost focus
}
}
}
我需要 https://doc.qt.io/qt-5/qml-qtquick-textinput.html#editingFinished-signal 的模拟。
因此,当用户按下 enter/space 时,将焦点更改为我需要信号的另一个项目。
问题是 editingFinished 对我没用。它仅在以下情况下有效
没有 mask/validator,在其他情况下如果 TextInput
是 invalid/incomplete 状态,
没有编辑完成信号。所以我想要它仿真。
我无法在 C++ 中继承 QQuickTextInput
,因为它是私有的 class。
我可以在 QML 中继承 TextInput
,但是如何在 QML class 中获取 focusOutEvent
继承 TextInput
?
您可以在 activeFocus
属性 上使用来检查对象是否具有焦点。
TextInput {
onActiveFocusChanged: {
if (activeFocus) {
// Gained focus
} else {
// Lost focus
}
}
}