Skip to content

Commit eeba2de

Browse files
committed
fix: forward InputMethodQuery to searchEdit for correct IME candidate window positioning
Override inputMethodQuery() virtual function in InputEventItem to forward input method queries to searchEdit. When IME queries cursor position for candidate window placement, the function forwards the query to searchEdit and maps the returned cursor rectangle coordinates from searchEdit's local coordinate system to InputEventItem's coordinate system. This ensures the candidate window appears at the correct position near the search box while keeping focus on InputEventItem. Changes: - Add inputMethodSource property to InputEventItem for specifying the text control to forward queries to - Override inputMethodQuery() to forward queries and map coordinates for ImCursorRectangle - Set inputMethodSource to searchEdit and add focus property in FullscreenFrame and WindowedFrame - Remove redundant ImEnabled override as SearchEdit already returns correct state 重写 InputEventItem 的 inputMethodQuery() 虚函数,将输入法查询转发给 searchEdit。当输入法查询光标位置以定位候选框时,该函数将查询转发给 searchEdit,并将返回的光标矩形坐标从 searchEdit 的局部坐标系映射到 InputEventItem 的坐标系。这确保候选框出现在搜索框附近的正确位置,同时焦点保持在 InputEventItem 上。 修改内容: - 为 InputEventItem 添加 inputMethodSource 属性,用于指定转发查询的文本控件 - 重写 inputMethodQuery() 以转发查询并映射 ImCursorRectangle 的坐标 - 在 FullscreenFrame 和 WindowedFrame 中设置 inputMethodSource 为 searchEdit 并添加 focus 属性 - 移除冗余的 ImEnabled 覆盖,因为 SearchEdit 已经返回正确状态 PMS: BUG-301743
1 parent 3cc4074 commit eeba2de

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

inputeventitem.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44
#include "inputeventitem.h"
@@ -12,6 +12,33 @@ InputEventItem::InputEventItem()
1212
qApp->installEventFilter(this);
1313
}
1414

15+
QQuickItem* InputEventItem::inputMethodSource() const
16+
{
17+
return m_inputMethodSource;
18+
}
19+
20+
void InputEventItem::setInputMethodSource(QQuickItem* source)
21+
{
22+
if (m_inputMethodSource != source) {
23+
m_inputMethodSource = source;
24+
Q_EMIT inputMethodSourceChanged();
25+
}
26+
}
27+
28+
QVariant InputEventItem::inputMethodQuery(Qt::InputMethodQuery query) const
29+
{
30+
if (m_inputMethodSource) {
31+
if (query == Qt::ImCursorRectangle) {
32+
QVariant result = m_inputMethodSource->inputMethodQuery(query);
33+
QRectF rect = result.toRectF();
34+
QPointF mapped = m_inputMethodSource->mapToItem(this, rect.topLeft());
35+
rect.moveTopLeft(mapped);
36+
return rect;
37+
}
38+
}
39+
return QQuickItem::inputMethodQuery(query);
40+
}
41+
1542
bool InputEventItem::eventFilter(QObject *obj, QEvent *event) {
1643
if (event->type() == QEvent::InputMethod && (this->children().contains(obj) || obj == this)) {
1744
QInputMethodEvent *inputMethodEvent = static_cast<QInputMethodEvent *>(event);

inputeventitem.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44
#ifndef INPUTEVENTITEM_H
@@ -12,14 +12,24 @@ class InputEventItem : public QQuickItem
1212
{
1313
Q_OBJECT
1414
QML_ELEMENT
15+
Q_PROPERTY(QQuickItem* inputMethodSource READ inputMethodSource WRITE setInputMethodSource NOTIFY inputMethodSourceChanged)
1516
public:
1617
InputEventItem();
1718

19+
QQuickItem* inputMethodSource() const;
20+
void setInputMethodSource(QQuickItem* source);
21+
22+
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
23+
1824
protected:
1925
bool eventFilter(QObject *obj, QEvent *event) override;
2026

2127
signals:
2228
void inputReceived(const QString &input);
29+
void inputMethodSourceChanged();
30+
31+
private:
32+
QQuickItem* m_inputMethodSource = nullptr;
2333
};
2434

2535
#endif // INPUTEVENTITEM_H

qml/FullscreenFrame.qml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import 'windowed' as WindowedLaunchpad
1818
InputEventItem {
1919
anchors.fill: parent
2020
objectName: "FullscreenFrame-InputEventItem"
21+
inputMethodSource: searchEdit
22+
focus: true
2123

2224
property Palette appTextColor: Palette {
2325
normal {

qml/windowed/WindowedFrame.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import "."
1616
InputEventItem {
1717
id: baseLayer
1818
objectName: "WindowedFrame-BaseLayer"
19+
inputMethodSource: bottomBar.searchEdit
1920

2021
visible: true
2122
focus: true

0 commit comments

Comments
 (0)