aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktextedit.cpp
diff options
context:
space:
mode:
authorVladimir Belyavsky <belyavskyv@gmail.com>2022-06-08 15:51:45 +0300
committerShawn Rutledge <shawn.rutledge@qt.io>2022-06-16 10:49:15 +0000
commit175dfd25c25fedee490c0578d34c2467cef83b00 (patch)
tree3209cccd8d902d87551341af9003f402db5f693f /src/quick/items/qquicktextedit.cpp
parentabc85505933a64cbceedd8e6fbc60288ac56fc1a (diff)
Fix TextEdit/TextArea mouse cursor shape handling logic
Previously IBeamCursor was wrongly shown in case when TextEdit was readonly and not selectable by mouse. Now ArrowCursor will be shown in such case. Additionally removed own mouse cursor shape handling logic in TextArea, so it will be unified now with derived logic from TextEdit. This is a change from 23f78b6b76fb9350a472485e34857e1a4842e5d3: we no longer attempt to restore a cursor that was set via setCursor(). [ChangeLog][QtQuick][TextEdit] TextEdit and TextArea now set their own mouse cursors more consistently, but without regard for any external call to setCursor(). Fixes: QTBUG-104089 Pick-to: 6.3 6.4 Change-Id: Iba4e0cb55d555b0f360d7856346ff9e8393b9e1e Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquicktextedit.cpp')
-rw-r--r--src/quick/items/qquicktextedit.cpp42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp
index 5a5af541ba..af99ebba19 100644
--- a/src/quick/items/qquicktextedit.cpp
+++ b/src/quick/items/qquicktextedit.cpp
@@ -1568,15 +1568,20 @@ bool QQuickTextEdit::selectByMouse() const
void QQuickTextEdit::setSelectByMouse(bool on)
{
Q_D(QQuickTextEdit);
- if (d->selectByMouse != on) {
- d->selectByMouse = on;
- setKeepMouseGrab(on);
- if (on)
- d->control->setTextInteractionFlags(d->control->textInteractionFlags() | Qt::TextSelectableByMouse);
- else
- d->control->setTextInteractionFlags(d->control->textInteractionFlags() & ~Qt::TextSelectableByMouse);
- emit selectByMouseChanged(on);
- }
+ if (d->selectByMouse == on)
+ return;
+
+ d->selectByMouse = on;
+ setKeepMouseGrab(on);
+ if (on)
+ d->control->setTextInteractionFlags(d->control->textInteractionFlags() | Qt::TextSelectableByMouse);
+ else
+ d->control->setTextInteractionFlags(d->control->textInteractionFlags() & ~Qt::TextSelectableByMouse);
+
+#if QT_CONFIG(cursor)
+ d->updateMouseCursorShape();
+#endif
+ emit selectByMouseChanged(on);
}
/*!
@@ -1639,6 +1644,9 @@ void QQuickTextEdit::setReadOnly(bool r)
#if QT_CONFIG(im)
updateInputMethod(Qt::ImEnabled);
#endif
+#if QT_CONFIG(cursor)
+ d->updateMouseCursorShape();
+#endif
q_canPasteChanged();
emit readOnlyChanged(r);
if (!d->selectByKeyboardSet)
@@ -2431,7 +2439,7 @@ void QQuickTextEditPrivate::init()
updateDefaultTextOption();
q->updateSize();
#if QT_CONFIG(cursor)
- q->setCursor(Qt::IBeamCursor);
+ updateMouseCursorShape();
#endif
}
@@ -2715,9 +2723,8 @@ void QQuickTextEdit::q_linkHovered(const QString &link)
emit linkHovered(link);
#if QT_CONFIG(cursor)
if (link.isEmpty()) {
- setCursor(d->cursorToRestoreAfterHover);
+ d->updateMouseCursorShape();
} else if (cursor().shape() != Qt::PointingHandCursor) {
- d->cursorToRestoreAfterHover = cursor().shape();
setCursor(Qt::PointingHandCursor);
}
#endif
@@ -2728,9 +2735,8 @@ void QQuickTextEdit::q_markerHovered(bool hovered)
Q_D(QQuickTextEdit);
#if QT_CONFIG(cursor)
if (!hovered) {
- setCursor(d->cursorToRestoreAfterHover);
+ d->updateMouseCursorShape();
} else if (cursor().shape() != Qt::PointingHandCursor) {
- d->cursorToRestoreAfterHover = cursor().shape();
setCursor(Qt::PointingHandCursor);
}
#endif
@@ -3001,6 +3007,14 @@ bool QQuickTextEditPrivate::isLinkHoveredConnected()
IS_SIGNAL_CONNECTED(q, QQuickTextEdit, linkHovered, (const QString &));
}
+#if QT_CONFIG(cursor)
+void QQuickTextEditPrivate::updateMouseCursorShape()
+{
+ Q_Q(QQuickTextEdit);
+ q->setCursor(q->isReadOnly() && !q->selectByMouse() ? Qt::ArrowCursor : Qt::IBeamCursor);
+}
+#endif
+
/*!
\qmlsignal QtQuick::TextEdit::linkHovered(string link)
\since 5.2