1 Star 0 Fork 18

xingwei-liu/qt5-qtbase

forked from src-anolis-os/qt5-qtbase 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
QTBUG002-85088-QGraphicsView-show-error-after-lose-focus.patch 3.64 KB
一键复制 编辑 原始数据 按行查看 历史
xingwei-liu 提交于 2022-10-12 16:54 . feature: add patchs for DDE
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xingwei-liu/qt5-qtbase.git
git@gitee.com:xingwei-liu/qt5-qtbase.git
xingwei-liu
qt5-qtbase
qt5-qtbase
a8

搜索帮助

0d507c66 1850385 C8b1a773 1850385