summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets
diff options
context:
space:
mode:
authorDaniel Teske <qt@squorn.de>2017-06-27 15:12:05 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2017-07-20 13:46:26 +0000
commit854fdaaf76873a4f5c6d5a5046b35bc8152fcc24 (patch)
tree6965008116d8ec8020a26ecd82aaaa22967d1e72 /src/widgets/widgets
parentd39ec44e1937c354d8770c5f0257d33b13272141 (diff)
QLineEdit: Add selectionEnd() and selectionLength()
Getting the end position of the selection was not possible. [ChangeLog][QtWidgets][QLineEdit] Added selectionEnd(), selectionLength(), complementing selectionStart(). Change-Id: Iaecc624063d7c043f9502351f07eb76f869e86f1 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r--src/widgets/widgets/qlineedit.cpp27
-rw-r--r--src/widgets/widgets/qlineedit.h2
2 files changed, 29 insertions, 0 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 4ac8118c87..f859ec0ddb 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -954,6 +954,8 @@ QString QLineEdit::selectedText() const
line edit or -1 if no text is selected.
\sa selectedText()
+ \sa selectionEnd()
+ \sa selectionLength()
*/
int QLineEdit::selectionStart() const
@@ -962,8 +964,33 @@ int QLineEdit::selectionStart() const
return d->control->selectionStart();
}
+/*!
+ Returns the index of the character directly after the selection
+ in the line edit or -1 if no text is selected.
+ \since 5.10
+ \sa selectedText()
+ \sa selectionStart()
+ \sa selectionLength()
+*/
+int QLineEdit::selectionEnd() const
+{
+ Q_D(const QLineEdit);
+ return d->control->selectionEnd();
+}
+/*!
+ Returns the length of the selection.
+ \since 5.10
+
+ \sa selectedText()
+ \sa selectionStart()
+ \sa selectionEnd()
+*/
+int QLineEdit::selectionLength() const
+{
+ return selectionEnd() - selectionStart();
+}
/*!
Selects text from position \a start and for \a length characters.
diff --git a/src/widgets/widgets/qlineedit.h b/src/widgets/widgets/qlineedit.h
index 4d32b11f06..d84eeedaf6 100644
--- a/src/widgets/widgets/qlineedit.h
+++ b/src/widgets/widgets/qlineedit.h
@@ -155,6 +155,8 @@ public:
bool hasSelectedText() const;
QString selectedText() const;
int selectionStart() const;
+ int selectionEnd() const;
+ int selectionLength() const;
bool isUndoAvailable() const;
bool isRedoAvailable() const;