Вы должны включить атрибут Qt::WA_InputMethodEnabled
в дополнение к переопределению метода inputMethodEvent
:
#include <QtWidgets>
class Widget: public QWidget{
public:
Widget(QWidget *parent=nullptr): QWidget(parent){
<b>setAttribute(Qt::WA_InputMethodEnabled, true);</b>
}
protected:
void keyPressEvent(QKeyEvent *event){
qDebug() << "keyPressEvent" << event->text();
QWidget::keyPressEvent(event);
}
<b>void inputMethodEvent(QInputMethodEvent *event){
qDebug() << "inputMethodEvent" << event->commitString();
QWidget::inputMethodEvent(event);
}</b>
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}