代码拉取完成,页面将自动刷新
同步操作将从 src-anolis-os/qt5-qtbase 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 24149dcbfa0c63d8429cdbb5cc249ad4beada387 Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Mon, 4 Jul 2022 18:30:01 +0800
Subject: [PATCH] QTBUG002-85088-QGraphicsView-show-error-after-lose-focus
---
src/widgets/graphicsview/qgraphicsscene.cpp | 9 ++++-
.../qgraphicsscene/tst_qgraphicsscene.cpp | 37 ++++++++++++++++++-
2 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp
index a428329a..75199f84 100644
--- a/src/widgets/graphicsview/qgraphicsscene.cpp
+++ b/src/widgets/graphicsview/qgraphicsscene.cpp
@@ -4230,8 +4230,13 @@ void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
void QGraphicsScene::inputMethodEvent(QInputMethodEvent *event)
{
Q_D(QGraphicsScene);
- if (d->focusItem && (d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod))
- d->sendEvent(d->focusItem, event);
+ 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);
+
}
/*!
diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
index 7e5d94da..c3e49131 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -289,6 +289,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();
@@ -3868,7 +3869,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));
@@ -3943,6 +3944,40 @@ void tst_QGraphicsScene::dispatchHoverOnPress()
}
}
+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);
+}
+
+
void tst_QGraphicsScene::initialFocus_data()
{
QTest::addColumn<bool>("activeScene");
--
2.31.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。