![]() |
Home · All Classes · All Functions · Overviews |
Files:
The Maemo 5 Zoom example shows how to make use of the zoom keys on a Maemo 5 device.
Note that, by default, the zoom keys are used for setting the volume on the device. Any application that wants to use zoom keys for its own purposes has to grab them first, and should release them when not needed anymore.
#include <QtGui/QX11Info> #include <X11/Xlib.h> #include <X11/Xatom.h>
Grabbing the zoom keys is done by setting an X11 Atom on the top-level widget. For that, we need to include Qt's X11 support headers as well as X11 headers.
For platform independent code, surround them with #ifdef Q_WS_MAEMO_5.
void grabZoomKeys(bool grab) { if (!winId()) { qWarning("Can't grab keys unless we have a window id"); return; } unsigned long val = (grab) ? 1 : 0; Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False); if (!atom) { qWarning("Unable to obtain _HILDON_ZOOM_KEY_ATOM. This example will only work " "on a Maemo 5 device!"); return; } XChangeProperty (QX11Info::display(), winId(), atom, XA_INTEGER, 32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1); }
First, XInternAtom is used to get the atom id of the _HILDON_ZOOM_KEY_ATOM. If no such atom exists, the application is most probably not running on a Maemo 5 device.
Then, XChangeProperty is used to set the atom. This tells the system that this top-level widget wants to grab the zoom buttons.
void keyPressEvent(QKeyEvent* event) { switch (event->key()) { case Qt::Key_F7: progressBar->setValue(progressBar->value() + 1); event->accept(); break; case Qt::Key_F8: progressBar->setValue(progressBar->value() - 1); event->accept(); break; } QWidget::keyPressEvent(event); }
The zoom keys are mapped to F7 and F8 by default.
Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt 4.6.2 |