输入法是否阻止 QLineEdit 接收 KeyPressEvent?

发布于 2024-09-24 23:10:22 字数 1956 浏览 2 评论 0原文

我将此错误发送给 Qt 团队: http://bugreports.qt-project.org/browse/QTBUG-13726 这是描述:

QLineEdit/QTextEdit does not receive keyPressEvent on N97 我有一个继承自 QLinedEdit 的自定义小部件,在这个小部件中我覆盖 event(QEvent * event)、keyPressEvent(QKeyEvent *event) 和 keyReleaseEvent(QKeyEvent *event )。当我在 N97 设备上调试代码时,当我按键盘上的任意键时,事件将按如下方式传递:

  1. event(QEvent * events) 被调用,事件类型设置为 KeyRelease。

  2. keyReleaseEvent(QKeyEvent *event ) 被调用。

并且 keyPressEvent 从未被调用!

如果我按 Enter、BackSpace、操作键、左、右、下、上,事件将按如下方式传递:

  1. event(QEvent * events) 被调用,事件类型设置为 KeyPress。

  2. keyPressEvent(QKeyEvent *event ) 被调用。

  3. event(QEvent * events) 被调用,事件类型设置为 KeyRelease。

  4. keyReleaseEvent(QKeyEvent *event ) 被调用。

这是正确的。

如何重现:

#include <QKeyEvent>
#include <QMessageBox>
#include <QLineEdit>
#include <QTextEdit>
#include <QDebug>


class MyWidget : public QLineEdit { Q_OBJECT public: MyWidget(QWidget *parent=0); void keyPressEvent(QKeyEvent * event); void keyReleaseEvent(QKeyEvent * event ); bool event(QEvent *event); };

MyWidget::MyWidget(QWidget *parent)
:QLineEdit(parent)

{ setText("Hola"); }
void MyWidget::keyPressEvent(QKeyEvent *event) { QLineEdit::keyPressEvent(event); }

void MyWidget::keyReleaseEvent(QKeyEvent *event ) { QLineEdit::keyReleaseEvent(event); }

bool MyWidget::event(QEvent *event ) {
switch( event->type() ) { case QEvent::KeyPress: QLineEdit::event(event); break; case QEvent::KeyRelease: QLineEdit::event(event); break; default: QLineEdit::event(event); }

}

如果我继承QTextEdit,也会出现同样的问题

并且我得到了这个重现:

这不就是因为输入法吗?

任何人都可以向我解释他所说的“输入方法”是什么意思,以及它与接收到的事件有何关系,我尝试使用 setInputMethodHints() 和 inputMethodEvent() 但没有成功。

I send this bug to Qt team:
http://bugreports.qt-project.org/browse/QTBUG-13726
and here is the description:

QLineEdit/QTextEdit doesn't receive keyPressEvent on N97
I have a custom widget which inherits from QLinedEdit, in this widget I override event(QEvent * event), keyPressEvent(QKeyEvent *event) and keyReleaseEvent(QKeyEvent *event ). When I debugged the code on N97 device, when I press any key on the keypad the events are delivered as follows:

  1. event(QEvent * events) gets called with event type set to KeyRelease.

  2. keyReleaseEvent(QKeyEvent *event ) gets called.

and keyPressEvent was never called !!

if I press Enter, BackSpace, action keys, left, right, down, up, the events are delivered as follows:

  1. event(QEvent * events) gets called with event type set to KeyPress.

  2. keyPressEvent(QKeyEvent *event ) gets called.

  3. event(QEvent * events) gets called with event type set to KeyRelease.

  4. keyReleaseEvent(QKeyEvent *event ) gets called.

which is correct.

How to reproduce:

#include <QKeyEvent>
#include <QMessageBox>
#include <QLineEdit>
#include <QTextEdit>
#include <QDebug>


class MyWidget : public QLineEdit { Q_OBJECT public: MyWidget(QWidget *parent=0); void keyPressEvent(QKeyEvent * event); void keyReleaseEvent(QKeyEvent * event ); bool event(QEvent *event); };

MyWidget::MyWidget(QWidget *parent)
:QLineEdit(parent)

{ setText("Hola"); }
void MyWidget::keyPressEvent(QKeyEvent *event) { QLineEdit::keyPressEvent(event); }

void MyWidget::keyReleaseEvent(QKeyEvent *event ) { QLineEdit::keyReleaseEvent(event); }

bool MyWidget::event(QEvent *event ) {
switch( event->type() ) { case QEvent::KeyPress: QLineEdit::event(event); break; case QEvent::KeyRelease: QLineEdit::event(event); break; default: QLineEdit::event(event); }

}

The same problem appears if I inherits from the QTextEdit

and I've got this replay:

Isn't that just because of the input methods?

can anyone explain to me what he means by "input methods", and how it is related to the received events, I tried with setInputMethodHints() and inputMethodEvent() without success.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以歌曲疗慰 2024-10-01 23:10:22

在 Symbian 上,Window 服务器将按键事件发送到 FEP(前端处理器),FEP 反过来向控件询问其输入功能(请参阅 http:// developer.symbian.org/main/documentation/reference/s3/pdk/GUID-FCEDC338-61CA-5D10-A8DB-E44A3EBBDE5E-GENID-1-10-1-3-1-1-9-1-3-1。 html 和 TCoeInputCapability)。我认为这就是错误报告的评论所指的内容。

Symbian 中的 OfferKeyEventL 功能是作为责任链实现的,这意味着如果链中的某个控件可以处理按键事件,则该事件将被消耗,链中的后续控件将不会意识到它。

因此,要么由于未设置输入功能而导致事件被 FEP 丢弃(尽管我不知道如何通过 Qt 设置它们),要么事件在链的早期被消耗。

On Symbian, the Window server sends key events to the FEP (Front End Processor) which in turn asks the control for its input capabilities (see http://developer.symbian.org/main/documentation/reference/s3/pdk/GUID-FCEDC338-61CA-5D10-A8DB-E44A3EBBDE5E-GENID-1-10-1-3-1-1-9-1-3-1.html, and TCoeInputCapabilities). I think this is what the comment to the bug report referred to.

The OfferKeyEventL functionality in Symbian is implemented as a Chain of Responsibility, which means that if a control in the chain can handle the key event, it is consumed and subsequent controls in the chain will not be aware of it.

So, either the event is discarded by the FEP due to input capabilities not being set (though I do not know how to set them through Qt) or the event is consumed earlier in the chain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文