QGraphicsTextItem无法更改64位版本中的输入法

2024-05-23 21:50:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是pyqt5.4.2-x64+python3.4 64位。 遗憾的是QGraphicsTextItem无法更改输入法,在示例/widgets/graphicsview/digramscene中的演示中,QGraphicsTextItem只能接受ascii字符,我无法向它输入中文。 但如果我换成32位版本,就没有问题了。 你有解决办法吗?你知道吗

谢谢!你知道吗


Tags: 版本示例asciiwidgets字符x64输入法解决办法
1条回答
网友
1楼 · 发布于 2024-05-23 21:50:52

您应该像这样调用QGraphicsItem提供的方法:

QGraphicsItem::setFlag(QGraphicsItem::ItemAcceptsInputMethod, true);

更重要的是,如果您继承了QGraphicsTextItem或其他内容,请重写keyReleaseEvent以便将事件传播到父级。这样,你就可以完成这项工作了。看起来是这样的:

void YourGraphicsItem::keyReleaseEvent(QKeyEvent* event)
{
    QGraphicsTextItem::keyPressEvent(event);
}

相关问题 更多 >