summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/widgets/qlineedit.h1
-rw-r--r--src/plugins/accessible/widgets/simplewidgets.cpp19
-rw-r--r--tests/auto/qaccessibility/tst_qaccessibility.cpp10
3 files changed, 27 insertions, 3 deletions
diff --git a/src/gui/widgets/qlineedit.h b/src/gui/widgets/qlineedit.h
index 48ff06b..c14d188 100644
--- a/src/gui/widgets/qlineedit.h
+++ b/src/gui/widgets/qlineedit.h
@@ -273,6 +273,7 @@ Q_SIGNALS:
private:
friend class QAbstractSpinBox;
+ friend class QAccessibleLineEdit;
#ifdef QT_KEYPAD_NAVIGATION
friend class QDateTimeEdit;
#endif
diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp
index 46d76f0..126045e 100644
--- a/src/plugins/accessible/widgets/simplewidgets.cpp
+++ b/src/plugins/accessible/widgets/simplewidgets.cpp
@@ -51,6 +51,7 @@
#include <qgroupbox.h>
#include <qlcdnumber.h>
#include <qlineedit.h>
+#include <private/qlineedit_p.h>
#include <qstyle.h>
#include <qstyleoption.h>
@@ -876,10 +877,22 @@ int QAccessibleLineEdit::cursorPosition()
return lineEdit()->cursorPosition();
}
-QRect QAccessibleLineEdit::characterRect(int /*offset*/, CoordinateType /*coordType*/)
+QRect QAccessibleLineEdit::characterRect(int offset, CoordinateType coordType)
{
- // QLineEdit doesn't hand out character rects
- return QRect();
+ int left, top, right, bottom;
+ lineEdit()->getTextMargins(&left, &top, &right, &bottom);
+ int x = lineEdit()->d_func()->control->cursorToX(offset);
+ int y = top;
+ QFontMetrics fm(lineEdit()->font());
+ const QString ch = text(offset, offset + 1);
+ int w = fm.width(ch);
+ int h = fm.height();
+
+ QRect r(x, y, w, h);
+ if (coordType == QAccessible2::RelativeToScreen)
+ r.moveTo(lineEdit()->mapToGlobal(r.topLeft()));
+
+ return r;
}
int QAccessibleLineEdit::selectionCount()
diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp
index 297e853..c42269b 100644
--- a/tests/auto/qaccessibility/tst_qaccessibility.cpp
+++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp
@@ -3150,6 +3150,16 @@ void tst_QAccessibility::lineEditTest()
QCOMPARE(textIface->textAtOffset(5, QAccessible2::LineBoundary,&start,&end), cite);
QCOMPARE(textIface->textAtOffset(5, QAccessible2::NoBoundary,&start,&end), cite);
+
+ // characterRect()
+ le3->show();
+ QTest::qWaitForWindowShown(le3);
+ const QRect lineEditRect = iface->rect(0);
+ // Only first 10 characters, check if they are within the bounds of line edit
+ for (int i = 0; i < 10; ++i) {
+ QVERIFY(lineEditRect.contains(textIface->characterRect(i, QAccessible2::RelativeToScreen)));
+ }
+
delete iface;
delete toplevel;
QTestAccessibility::clearEvents();