You have to enable the Qt::WA_InputMethodEnabled
attribute in addition to override the inputMethodEvent
method:
#include <QtWidgets>
class Widget: public QWidget{
public:
Widget(QWidget *parent=nullptr): QWidget(parent){
setAttribute(Qt::WA_InputMethodEnabled, true);
}
protected:
void keyPressEvent(QKeyEvent *event){
qDebug() << "keyPressEvent" << event->text();
QWidget::keyPressEvent(event);
}
void inputMethodEvent(QInputMethodEvent *event){
qDebug() << "inputMethodEvent" << event->commitString();
QWidget::inputMethodEvent(event);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}