QAccessible and QPushButton
-
At first, sorry for my English)) Please, can somebody help me to understand how to enable Accessibility in Qt. Particulary i'm interested in VoiceOver (mac). Here i tried to make some example with simple programm - just one button and VoiceOver support.
@
//WidgetInterface.h
#ifndef ACCESSIBLE_H
#define ACCESSIBLE_H#include <QAccessibleWidget>
#include <QRect>
#include <QWidget>class AccessiblePushButton : public QAccessibleWidget
{
public:
AccessiblePushButton(QWidget *widget, Role role = Client,
const QString & name = QString()) : QAccessibleWidget(widget, role, name){}
int childCount() const{ return 0; }
QRect rect(int child) const
{
return widget()->rect();
}
QString text(Text text, int child) const
{
switch (text)
{
case Value:
return "Hello";
case Name:
return "QPushButton";
case Description:
return "This is pushbutton";
case Help:
return "Help for pushbutton";
default:
break;
}
return QAccessibleWidget::text(text, child);
}
Role role(int child) const{ return QAccessible::PushButton; }};
#endif@
@#include <QtGui/QApplication>
#include <QPushButton>
#include <QAccessibleInterface>
#include "WidgetInterface.h"QAccessibleInterface *buttonFactory(const QString &classname, QObject *object)
{
QAccessibleInterface *interface = 0;if (classname == "QPushButton") interface = new AccessiblePushButton(static_cast<QWidget *>(object)); return interface;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QAccessible::installFactory(buttonFactory);
QPushButton pb("Hello");
pb.show();
return a.exec();
}@pro file
@
QT += core guiTARGET = test_voice_over
TEMPLATE = appSOURCES += main.cpp
HEADERS += WidgetInterface.h
QTPLUGIN += qtaccessiblewidgets
@Or if someone has completelly, working example - please help))
I will be very grateful! ))thanks in advance!
-
actually Qt already provides accessibility implementations for the base widgets (e.g. QPushButton, ...)
Just copy the accessiblewidgets Qt plugin so your application loads it.
The plugin can be found in the standard Qt plugin path.If you built Qt yourself make sure you have built it with accessible support.
-
[quote author="raven-worx" date="1390217125"]actually Qt already provides accessibility implementations for the base widgets (e.g. QPushButton, ...)
Just copy the accessiblewidgets Qt plugin so your application loads it.
The plugin can be found in the standard Qt plugin path.If you built Qt yourself make sure you have built it with accessible support.[/quote]
GreatThanks! I found that the Internet is not much documentation and examples on this subject...
I guess i need to set Accessiblename and AccessibleDescription - that's right? And VoiceOver will read accessibleName when focus on my widget? -
Maybe they will already be set implicitly also by Qt at appropriate places, but make sure and set them manually.
[quote author="Kudaiv" date="1390217637"]
I guess i need to set Accessiblename and AccessibleDescription - that's right? And VoiceOver will read accessibleName when focus on my widget?
[/quote]
Can't answer that, sry. Never used accessibility on a Mac. -
Ok, i found this post http://stackoverflow.com/questions/3893560/qt-accessible-widgets and it seems easy, so tried like this
@
#include <QLabel>
#include <QtPlugin>Q_IMPORT_PLUGIN(qtaccessiblewidgets)
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel pb("Hello");
pb.setAccessibleName("Helloo");
pb.setAccessibleDescription("Button");
pb.show();
return a.exec();
}
@@QT += core gui
TARGET = test_voice_over
TEMPLATE = appSOURCES += main.cpp
HEADERS += WidgetInterface.h
QTPLUGIN += qtaccessiblewidgets
@
every time i've got this error
"qt_plugin_instance_qtaccessiblewidgets()", referenced from:
global constructors keyed to mainin main.o
ld: symbol(s) not found for architecture x86_64what's wrong?
-
you do not need this line in your pro-File:
QTPLUGIN += qtaccessiblewidgetsthe qtaccessiblewidgets plugin is loaded automatically at runtime ifQt is able to find it.
You only need this line when you build your app statically. Which doesn't look so seeing the rest of the pro-File.
-
Thank you! And now i think that my Qt were build with no-accessibility...
and@qt_plugin_instance_qtaccessiblewidgets()”, referenced from: global constructors keyed to mainin main.o
ld: symbol(s) not found for architecture x86_64
@
testifies about it. But i can find qtaccessiblewidgets plugin in standart plugin path... -
[quote author="raven-worx" date="1390375476"]you do not need this line in your pro-File:
QTPLUGIN += qtaccessiblewidgetsthe qtaccessiblewidgets plugin is loaded automatically at runtime ifQt is able to find it.
You only need this line when you build your app statically. Which doesn't look so seeing the rest of the pro-File.
[/quote]Q_IMPORT_PLUGIN(qtaccessiblewidgets)
this need for static plugins too? -
yes, see "this":http://qt-project.org/doc/qt-4.8/plugins-howto.html#static-plugins.
If you link your application dynamically to Qt you don't have to worry about anything in your code. Just that the plugins are located in the correct path. -
it's funny but qt can't load libqtaccessiblewidgets.dylib in runtime
(i'm using DYLD_PRINT_LIBRARIES=1 QT_DEBUG_PLUGINS=1 myapp)
so i'm doing something like this
@ QPluginLoader loader(a.applicationDirPath() + "/../PlugIns/accessible/libqtaccessiblewidgets.dylib");
qDebug() << a.applicationDirPath();
bool isLoad = loader.load();
qDebug() << isLoad << " " << loader.errorString() ; @
and qt.conf on it's place! And nothing...
but when i'm using DYLD_PRINT_LIBRARIES=1 QT_DEBUG_PLUGINS=1 myapp i see this
QFactoryLoader::QFactoryLoader() looking at "/Users/sergey/test_voice_over/test_voice_over.app/Contents/PlugIns/accessible/libqtaccessiblewidgets.dylib"
keys ("QLineEdit", "QComboBox", "QAbstractSpinBox", "QSpinBox", "QDoubleSpinBox", "QScrollBar", "QSlider", "QAbstractSlider", "QToolButton", "QCheckBox", "QRadioButton", "QPushButton", "QAbstractButton", "QDialog", "QMessageBox", "QMainWindow", "QLabel", "QLCDNumber", "QGroupBox", "QStatusBar", "QProgressBar", "QMenuBar", "Q3PopupMenu", "QMenu", "QHeaderView", "QTabBar", "QToolBar", "QWorkspaceChild", "QSizeGrip", "QAbstractItemView", "QWidget", "QSplitter", "QSplitterHandle", "QTextEdit", "QPlainTextEdit", "QTipLabel", "QFrame", "QStackedWidget", "QToolBox", "QMdiArea", "QMdiSubWindow", "QWorkspace", "QDialogButtonBox", "QDial", "QRubberBand", "QTextBrowser", "QAbstractScrollArea", "QScrollArea", "QCalendarWidget", "QDockWidget")and trying to create simpliest app with one button with VoiceOver support
@int main(int argc, char *argv[])
{
QApplication a(argc, argv);QPluginLoader loader(a.applicationDirPath() + "/../PlugIns/accessible/libqtaccessiblewidgets.dylib"); qDebug() << a.applicationDirPath(); bool isLoad = loader.load(); qDebug() << isLoad << " " << loader.errorString() ; QPushButton pb("Hello button"); pb.show(); return a.exec();
}
@
WSAA works fine with this code... what's wrong with voice over? -
which version of Qt are you using? Qt 4 or Qt 5?
With Qt (5.1?) the accessible support has been "improved ":http://blog.qt.digia.com/blog/2012/06/18/qt-5-accessibility-apis/on Mac OS X.