Return correct accessible name when a label has rich text
authorJosé Millán Soto <fid@gpul.org>
Sun, 23 Sep 2012 09:46:21 +0000 (11:46 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 27 Sep 2012 04:07:27 +0000 (06:07 +0200)
When a QLabel was displaying rich text, the raw html was being returned as
accessible name. Now the plain text is returned.

Task-number: QTBUG-27302
Change-Id: I169d5eff527a0aef810af11d7712a362148974a5
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
src/plugins/accessible/widgets/simplewidgets.cpp

index 555289c..2015929 100644 (file)
@@ -55,6 +55,7 @@
 #include <qlineedit.h>
 #include <qstyle.h>
 #include <qstyleoption.h>
+#include <qtextdocument.h>
 #include <QtCore/qvarlengtharray.h>
 
 #ifdef Q_OS_MAC
@@ -392,7 +393,14 @@ QString QAccessibleDisplay::text(QAccessible::Text t) const
         str = widget()->accessibleName();
         if (str.isEmpty()) {
             if (qobject_cast<QLabel*>(object())) {
-                str = qobject_cast<QLabel*>(object())->text();
+                QLabel *label = qobject_cast<QLabel*>(object());
+                str = label->text();
+                if (label->textFormat() == Qt::RichText
+                    || (label->textFormat() == Qt::AutoText && Qt::mightBeRichText(str))) {
+                    QTextDocument doc;
+                    doc.setHtml(str);
+                    str = doc.toPlainText();
+                }
 #ifndef QT_NO_LCDNUMBER
             } else if (qobject_cast<QLCDNumber*>(object())) {
                 QLCDNumber *l = qobject_cast<QLCDNumber*>(object());