path: root/src/gui/kernel/qstylehints.cpp
diff options
authorElvis Angelaccio <>2017-10-26 18:22:14 +0200
committerElvis Angelaccio <>2018-02-03 16:34:05 +0000
commit4772ac90fa84a81292477a4c9a283437fb5d791e (patch)
treeff3966771c90647ed330511ab73d82b426fcda3e /src/gui/kernel/qstylehints.cpp
parent8db29d92df0ef9fbc39d88945d16a16f43edf20e (diff)
QLineEdit: implement quick text selection by mouse
This is a standard feature in GtkEntry widgets or HTML <input type="text"> elements. During a normal text selection by mouse (LeftButton press + mouse move event), it's now possible to quickly select all the text from the start of the selection to the end of the line edit by moving the mouse cursor down. By moving it up instead, all the text up to the start of the line edit gets selected. If the layout direction is right-to-left, the semantic of the mouse movement is inverted. This feature is only enabled if the y() of the mouse move event is bigger than a fixed threshold, to avoid unexpected selections in the normal case. This threshold is set by the QPlatformTheme and a value smaller than zero disables this feature. The threshold is updated whenever the style or the screen changes. [ChangeLog][QtWidgets][QLineEdit] Implemented quick text selection by mouse in QLineEdit. Change-Id: I4de33c2d11c033ec295de2b2ea81adf786324f4b Reviewed-by: Shawn Rutledge <>
Diffstat (limited to 'src/gui/kernel/qstylehints.cpp')
1 files changed, 36 insertions, 0 deletions
diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp
index 0850228ee5..b2d968c046 100644
--- a/src/gui/kernel/qstylehints.cpp
+++ b/src/gui/kernel/qstylehints.cpp
@@ -79,6 +79,7 @@ public:
, m_tabFocusBehavior(-1)
, m_uiEffects(-1)
, m_wheelScrollLines(-1)
+ , m_mouseQuickSelectionThreshold(-1)
int m_mouseDoubleClickInterval;
@@ -90,6 +91,7 @@ public:
int m_tabFocusBehavior;
int m_uiEffects;
int m_wheelScrollLines;
+ int m_mouseQuickSelectionThreshold;
@@ -537,4 +539,38 @@ void QStyleHints::setWheelScrollLines(int scrollLines)
emit wheelScrollLinesChanged(scrollLines);
+ Sets the mouse quick selection threshold.
+ \internal
+ \sa mouseQuickSelectionThreshold()
+ \since 5.11
+void QStyleHints::setMouseQuickSelectionThreshold(int threshold)
+ Q_D(QStyleHints);
+ if (d->m_mouseQuickSelectionThreshold == threshold)
+ return;
+ d->m_mouseQuickSelectionThreshold = threshold;
+ emit mouseDoubleClickIntervalChanged(threshold);
+ \property QStyleHints::mouseQuickSelectionThreshold
+ \brief Quick selection mouse threshold in QLineEdit.
+ This property defines how much the mouse cursor should be moved along the y axis
+ to trigger a quick selection during a normal QLineEdit text selection.
+ If the property value is less than or equal to 0, the quick selection feature is disabled.
+ \since 5.11
+int QStyleHints::mouseQuickSelectionThreshold() const
+ Q_D(const QStyleHints);
+ if (d->m_mouseQuickSelectionThreshold >= 0)
+ return d->m_mouseQuickSelectionThreshold;
+ return themeableHint(QPlatformTheme::MouseQuickSelectionThreshold, QPlatformIntegration::MouseQuickSelectionThreshold).toInt();