Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
None
-
5.11.3, 5.15.0
-
None
-
OS:deepin
Qt Version: Qt5.11.3.9
Compiler: x86_64-linux-gnu
Executed from Qt Creator in Debug mode.
-
-
3983afd48f27cdbb006720957ff34cf58f126ca5 (qt/qtbase/dev)
Description
step1:
create a Qt GUI project and coding main.cpp as fllow:
#include <QApplication> #include <QGraphicsScene> #include <QGraphicsView> #include <QGraphicsTextItem> int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsScene scene; QGraphicsView view(&scene); QGraphicsTextItem *simpleTextItem = new QGraphicsTextItem; simpleTextItem->setFlag(QGraphicsTextItem::ItemIsFocusScope); simpleTextItem->setTextInteractionFlags(Qt::TextEditorInteraction); simpleTextItem->setPlainText("QGraphicsTextItem"); scene.addItem(simpleTextItem); view.show(); return a.exec(); }
step2:
run application and change the system input method with chinese, and then input chinese into application QGraphicsTextItem, at this time,textItem will show preview text,click scence blank area or change window display or minimize window,the application TextItem will selected preview text. but when you click or drag mouse cursor,the preview text will disappear, if you do nothing, the preview text always show. ******this enclosure packet contains a error.gif will show process.
Reasons:
The reason for this bug is that after the TextItem loses focus, the focusItem in QGraphicsScene is already empty. When QGraphicsScene responds to the inputMethodEvent event again, since focusItem is already empty, focusItem will no longer deliver events.
fix:
The solution to this bug is to let the last input textitem continue to respond to the inputMethodEvent event. The modified code on(widgets/graphicsview/qgraphicsscene.cpp).
void QGraphicsScene::inputMethodEvent(QInputMethodEvent *event) { Q_D(QGraphicsScene); if (d->focusItem && (d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) { d->sendEvent(d->focusItem, event); return; } if (d->lastFocusItem && d->lastFocusItem != d->focusItem && (d->lastFocusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) d->sendEvent(d->lastFocusItem, event); }
effect:
When the textitem is in preview input, the focus is lost or the window is changed or the window is minimized, and the preview input text can be received.this enclosure packet contains a done.gif will show process.**