0ices 2021-06-30 11:05 采纳率: 60%
浏览 86
已采纳

Qt QGraphicsView如何使用中文输入法?

我在QScrollArea中可以通过设置setAttribute(Qt::WA_InputMethodEnabled);来使用中文输入法,但在QGraphicsView却无法做到,直接响应了keyPressEvent,不知道是什么原因 我测试了testAttribute(Qt::WA_InputMethodEnabled);结果在scene.addItem(item);这句前后输出转变为false,这是为什么呢

  • 写回答

2条回答 默认 最新

  • 0ices 2021-06-30 13:03
    关注

    该问题已解决,在源码中setScene和focusInEvent函数中会调用一私有函数updateInputMethodSensitivity,此函数源码注释写着

    /*! \internal

    Enables input methods for the view if and only if the current focus item of
    the scene accepts input methods. Call function whenever that condition has
    potentially changed.
    

    */

    所以在focusInEvent事件之后重新设置一下setAttribute(Qt::WA_InputMethodEnabled);即可实现想要的效果

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?