summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhang Hao <zhanghao@uniontech.com>2021-09-08 17:14:46 +0800
committerZhang Hao <zhanghao@uniontech.com>2021-09-18 00:55:36 +0000
commit33238ea2c63b372ee8795eaafbfc5a859a778f8d (patch)
tree0331c65ff9537493e5cfdf8b205250c606d642a6
parent1c6d6b7c0d7d7e8a96d1f7b2f259933910b2d481 (diff)
Fix QTextEdit cursor rectangle vertical positioning
When there are characters with different pointsize in QScriptLine, the value of si.descent is less than sl.descent, which will cause the y value of the cursor rectangle to be too large. If si.descent is less than sl.descent, the height of the cursor rectangle is equal to base plus si.descent. Amends e99a883bd382ca950192bd66cafb2a1de6394ce7 Fixes: QTBUG-96288 Done-with: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Pick-to: 6.1 6.2 Change-Id: I4a8566b32cfa75d8ca1a584f5e8e577c5c9caf0d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/gui/text/qtextlayout.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 70e6043231..ad5e827bdd 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -1289,13 +1289,16 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition
QFixed base = sl.base();
QFixed descent = sl.descent;
+ QFixed cursorDescent = descent;
bool rightToLeft = d->isRightToLeft();
if (itm >= 0) {
const QScriptItem &si = d->layoutData->items.at(itm);
if (si.ascent >= 0)
base = si.ascent;
- if (si.descent >= 0)
+ if (si.descent == 0)
descent = si.descent;
+ else if (si.descent > 0 && si.descent < descent)
+ cursorDescent = si.descent;
rightToLeft = si.analysis.bidiLevel % 2;
}
qreal y = position.y() + (sl.y + sl.base() + sl.descent - base - descent).toReal();
@@ -1306,7 +1309,7 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition
QPainter::CompositionMode origCompositionMode = p->compositionMode();
if (p->paintEngine()->hasFeature(QPaintEngine::RasterOpModes))
p->setCompositionMode(QPainter::RasterOp_NotDestination);
- p->fillRect(QRectF(x, y, qreal(width), (base + descent).toReal()), p->pen().brush());
+ p->fillRect(QRectF(x, y, qreal(width), (base + cursorDescent).toReal()), p->pen().brush());
p->setCompositionMode(origCompositionMode);
if (toggleAntialiasing)
p->setRenderHint(QPainter::Antialiasing, false);