Important: Please read the Qt Code of Conduct -

How inputMethodEvent work?

  • I create graphics editor. My application has View, Scene and QGraphicsTextItem. View has Qt::WA_InputMethodEnabled attribute set. I overriden inputMethodEvent in view:

    void WorkSpace::inputMethodEvent(QInputMethodEvent* event)
    	qDebug() << "WorksSpace inputMethodEvent";

    When I press some buttons on keyboard, the method does not invoke, as I expected. Futhermore, event does not propagade to scene and focused item. How inputMethodEvent work and how to make it work correctly?

  • Lifetime Qt Champion

    Why not use
    void QGraphicsView::keyPressEvent(QKeyEvent *event)

    I never used inputMethodEvent and its related classes and only seen it used for an onscreen keyboard implementation
    so I wonder what you try to do?

  • Yeah, I currently use keyPressEvent but I though inputMethodEvent would be better soulution. Has Qt some class for key processing and create string? I need to create string in my QGraphicsTexEdit, but I don't wan't to process every key for example backspace etc.

  • Lifetime Qt Champion

    Have a look at the Diagram example
    (its available directly in Creator)

    It uses
    to allow easy textinput with support for delete / backspace etc.

    Maybe that is enough for your use case ?

Log in to reply