diff options
author | Zhang Hao <zhanghao@uniontech.com> | 2020-06-30 10:08:36 +0800 |
---|---|---|
committer | Zhang Hao <zhanghao@uniontech.com> | 2020-09-18 09:17:37 +0800 |
commit | 3983afd48f27cdbb006720957ff34cf58f126ca5 (patch) | |
tree | ae6566fac7cee10e4035d91907c0df25398e3a2f /tests | |
parent | 18cda2f669acd303f540cda12cc9bb655a7f1282 (diff) |
QGraphicsView:QGraphicstextitem show error after lose focus
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.
Fixes:QTBUG-85088
Pick-to:5.15
Change-Id: I329054333c2adec133d35318761612aca3afcf0d
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 6b292bc713..94130e25bf 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -288,6 +288,7 @@ private slots: void taskQTBUG_15977_renderWithDeviceCoordinateCache(); void taskQTBUG_16401_focusItem(); void taskQTBUG_42915_focusNextPrevChild(); + void taskQTBUG_85088_previewTextfailWhenLostFocus(); private: QRect m_availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); @@ -3867,7 +3868,7 @@ void tst_QGraphicsScene::inputMethod() item->eventCalls = 0; QCoreApplication::sendEvent(&scene, &event); - QCOMPARE(item->eventCalls, 0); + QCOMPARE(item->eventCalls, callFocusItem ? 1 : 0); item->queryCalls = 0; scene.inputMethodQuery(Qt::InputMethodQuery(0)); @@ -4932,5 +4933,38 @@ void tst_QGraphicsScene::taskQTBUG_42915_focusNextPrevChild() QTest::keyEvent(QTest::Click, &view, Qt::Key_Tab); } +void tst_QGraphicsScene::taskQTBUG_85088_previewTextfailWhenLostFocus() +{ + QString str = "simpleTextItem"; + QGraphicsScene scene; + QGraphicsView view(&scene); + + QGraphicsTextItem *simpleTextItem = new QGraphicsTextItem; + simpleTextItem->setFlag(QGraphicsTextItem::ItemIsFocusScope); + simpleTextItem->setTextInteractionFlags(Qt::TextEditorInteraction); + simpleTextItem->setPlainText(str); + scene.addItem(simpleTextItem); + + scene.setFocusItem(simpleTextItem); + view.setGeometry(100, 100, 600, 400); + view.show(); + + QInputMethodEvent inputEvent; + QString &preedictStr = const_cast<QString &>(inputEvent.preeditString()); + preedictStr = str; + QApplication::sendEvent(&scene, &inputEvent); + QCOMPARE(simpleTextItem->toPlainText(), str); + + // focusItem will lose focus + QMouseEvent pressEvent(QEvent::MouseButtonPress, QPointF(0, 0), + Qt::LeftButton, Qt::NoButton, Qt::NoModifier); + QApplication::sendEvent(view.viewport(), &pressEvent); + + preedictStr.clear(); + inputEvent.setCommitString(str); + QApplication::sendEvent(&scene, &inputEvent); + QCOMPARE(simpleTextItem->toPlainText(), str + str); +} + QTEST_MAIN(tst_QGraphicsScene) #include "tst_qgraphicsscene.moc" |