Cross-Platform Accessibility Support in Qt 4Qt 4 allows developers to write cross-platform applications that are usable by visually impaired users as well as by users with other disabilities. Qt accessibility will make applications accessible to more users and opens the governmental market, where accessibility is often a requirement. General OverviewQt 3 already supports Microsoft Active Accessibility (MSAA) and Mac OS X Accessibility. Qt 4 closes the gap in Trolltech's accessibility offering by introducing support for AT-SPI on Unix/X11 systems. The accessibility classes themselves have been extended in various ways since Qt 3. We added new functions and new enum values, and revised the API to make it more consistent with the rest of Qt. We also added two properties to QWidget, accessibleName and accessibleDescription, that can be set in Qt Designer to provide basic help texts without having to write any code. Qt's accessibility architecture is as follows. Qt offers one generic interface, QAccessibleInterface, that can be used to wrap all widgets and objects (e.g., QPushButton). This single interface provides all the metadata necessary for the assistive technologies. Qt provides implementations of this interface for its built-in widgets as plugins. When you develop custom widgets, you can create custom subclasses of QAccessibleInterface and distribute them as plugins (using QAccessiblePlugin) or compile them into the application. Likewise, Qt's predefined accessibility support can be built as plugin (the default) or directly into the Qt library. The main advantage of using plugins is that the accessibility classes are only loaded into memory if they are actually used; they don't slow down the common case where no assistive technology is being used. In addition to QAccessibleInterface, Qt includes two convenience classes, QAccessibleObject and QAccessibleWidget, that provide the lowest common denominator of metadata (e.g., widget geometry, window title, basic help text). You can use them as base classes when wrapping your custom QObject or QWidget subclasses. Another new feature in Qt 4 is that Qt can now support other backends in addition to the predefined ones. This is done by subclassing QAccessibleBridge. Example CodeThe first example illustrates how to provide accessibility information for a custom widget. We can use QAccessibleWidget as a base class and reimplement various functions: class MyWidgetInterface : public QAccessibleWidget { public: MyWidgetInterface(QWidget *widget, Role role); QString text(Text text, int child) const; State state(int child) const; QString actionText(int action, Text text, int child) const; bool doAction(int action, int child, const QVariantList ¶ms); ... }; Here's how we would implement the doAction() function to call a function named click() on the wrapped MyWidget object when the user invokes the object's default action or "presses" it. bool MyWidgetInterface::doAction(int action, int child, const QVariantList ¶ms) { if (child || !widget()->isEnabled()) return false; switch (action) { case DefaultAction: case Press: { MyWidget *widget = qobject_cast<MyWidget *>(object()); if (widget) widget->click(); } return true; } return QAccessibleWidget::doAction(action, child, params); } To export the widget interface as a plugin, we must subclass QAccessibleFactory: QStringList MyFactory::keys() const { return QStringList() << "MyWidget" << "MyOtherWidget"; } QAccessibleInterface *MyFactory::create(const QString &className, QObject *object) { if (classname == "MyWidget") return new MyWidgetInterface(object); if (classname == "MyOtherWidget") return new MyOtherWidgetInterface(object); return 0; } Q_EXPORT_PLUGIN2(MyFactory) [Previous: The New Qt Designer] [Home] [Next: The Qt 4 Database GUI Layer] |
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
Le blog Digia au hasardCréer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut CuvelierLe blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.
CommunautéRessources
Liens utilesContact
Qt dans le magazine |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.3 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com