UI/Qt: Enable basic IME keyboard input for WebContentView

This makes dead keys work (e.g. typing ' and e results in é).
This commit is contained in:
Jelle Raaijmakers 2024-08-12 14:06:41 +02:00 committed by Tim Ledbetter
parent 4a42c97f4d
commit 7e57cc7b09
Notes: github-actions[bot] 2024-08-12 16:28:26 +00:00
2 changed files with 17 additions and 1 deletions

View file

@ -36,7 +36,6 @@
#include <QCursor>
#include <QGuiApplication>
#include <QIcon>
#include <QLineEdit>
#include <QMimeData>
#include <QMouseEvent>
#include <QPaintEvent>
@ -60,6 +59,7 @@ WebContentView::WebContentView(QWidget* window, RefPtr<WebView::WebContentClient
m_client_state.client = parent_client;
m_client_state.page_index = page_index;
setAttribute(Qt::WA_InputMethodEnabled, true);
setMouseTracking(true);
setAcceptDrops(true);
@ -346,6 +346,20 @@ void WebContentView::keyReleaseEvent(QKeyEvent* event)
enqueue_native_event(Web::KeyEvent::Type::KeyUp, *event);
}
void WebContentView::inputMethodEvent(QInputMethodEvent* event)
{
if (!event->commitString().isEmpty()) {
QKeyEvent keyEvent(QEvent::KeyPress, 0, Qt::NoModifier, event->commitString());
keyPressEvent(&keyEvent);
}
event->accept();
}
QVariant WebContentView::inputMethodQuery(Qt::InputMethodQuery) const
{
return QVariant();
}
void WebContentView::mouseMoveEvent(QMouseEvent* event)
{
if (!m_tooltip_override) {

View file

@ -61,6 +61,8 @@ public:
virtual void dropEvent(QDropEvent*) override;
virtual void keyPressEvent(QKeyEvent* event) override;
virtual void keyReleaseEvent(QKeyEvent* event) override;
virtual void inputMethodEvent(QInputMethodEvent*) override;
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const override;
virtual void showEvent(QShowEvent*) override;
virtual void hideEvent(QHideEvent*) override;
virtual void focusInEvent(QFocusEvent*) override;