Developer
truf | 13 August, 2011 22:40
Few days ago I had a chance to play for a wile with my Nokia N950. I've tried to port some Qt application from Symbian to Harmattan and unfortunately faced with lack of support of QWidget and QGraphicsView based applications in that platform. Some of my findings are below:
That seems a bit unfair for me as there are Qt 4.7.x libs preinstalled and QWidgets\QGraphicsView are still mainstream ways to develop UI for it. That might cause a lot of problems during the porting of Symbian\Maemo5 applications to Harmattan.
In my case the app i tried to port contains QGraphicsView with some pixmap elements in it and some QPushButtons with images over them (without text). So i'm luckely avoid QWidget-style problem.
Its launched on N950 without any changes in sources and looks great (of course due to devices screensize the images were smaller). But it had landscape orientation. And i spent a lot of time on fixing such a simple thing. Finally, i have managed to rotate UI using the following:
And one more step (that's actually the real reason of that post and the only thing I have to share). The system itself still treats your application window as landscape oriented. That mean, for example, that if the "Top slide closes the application" setting is switched on in your device it will not work correctly for your app window. Actually, it will but with wrong sliding direction (right side is top for landscape oriented windows). To fix this behavior and let system know that your window is portrait oriented you should call following function for your top-level widget:
Normal 0 false false false RU X-NONE X-NONE
Normal 0 false false false RU X-NONE X-NONE#ifdef Q_OS_UNIX
#include <QX11Info>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#endif
enum MyOrientation
{
Landscape = 0,
Portrait = 270,
LandscapeInverted = 180,
PortraitInverted = 90
};
static void writeX11OrientationAngleProperty(QWidget* widget, MyOrientation orientation= Portrait)
{
#ifdef Q_WS_X11
if (widget)
{
WId id = widget->winId();
Display *display = QX11Info::display();
if (!display) return;
Atom orientationAngleAtom = XInternAtom(display, "_MEEGOTOUCH_ORIENTATION_ANGLE", False);
XChangeProperty(display, id, orientationAngleAtom, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&orientation, 1);
}
#endif
}
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
Form f;
writeX11OrientationAngleProperty(&f);
f.showFullScreen();
return a.exec();
}
The code was copy-pasted and adopted from some MeeGo sources.
Unfortunately it just tells the system that your window orientation is changed, so OS can manage it accordingly. But it doesn't change orientation of content inside window so it doesn't affect window rendering.
Commentstruf | 01/09/2011, 13:37
Just realized that actually you HAVE TO use the code snippet above in all cases except you've rewrited your app in QML with Window and Page elements. Because otherwise your portrait app could be closed by wrong (landscape) swipe direction and you will fail the Nokia Store QA process with something like that:
SUMMARY: The application close when trying to suspend the application to the background.
STEPS TO REPRODUCE:
1. Download the content OTA。
2. Install and launch the content.
3. Suspend the application in the backgroung by swiping the screen form right to left.
ACTUAL RESULT: The application close.
EXPECTED RESULT: The application should not close when minimizing the application to recents by swiping: Left-Right, Right-Left, Down-Top. For Portrait applications, swiping from Top-Down should close the application and it should not appear in recents. For Landscape applications, swiping the device from Top-Down while holding the device in Landscape should close the application and it should not appear in recents.
AFFECTED DEVICES: N9 Firmware: xxx
truf | 11/10/2011, 20:14
There is a good sample project that showcase porting QWidget-based app to MeeGo 1.2 by adding all widgets in QGraphicsView. You can find it here:
https://gitorious.org/harmattanwidgetproxy
Readme:
https://gitorious.org/harmattanwidgetproxy/harmattanwidgetproxy/blobs/master/qmlproxy/README
q8phantom | 06/12/2011, 20:33
Thank you, this seems the ultimate solution for this problem I recieved today from OVI
Failed QA
SUMMARY: Application does not close when using the swipe down function.
STEPS TO REPRODUCE:
1. Download and install the aplication
2. Enable the option "Swipe down to close app" from Settings -> Device Display.
3. Launch to the application. If the application is a Portrait application, swipe from Top-down. If the application is a Landscape application, swipe from Top-down when holding the device in Landscape orientation.
ACTUAL RESULT: The application doesn't close when swiping from Top-Down.
EXPECTED RESULT: For Portrait applications, swiping from Top-Down should close the application and it should not appear in recents.
For Landscape applications, swiping from Top-Down while holding the device in Landscape orientation should close the application and it should not appear in recents.
Re: Some findings on application orientation in MeeGo 1.2 Harmattan
truf | 16/08/2011, 10:42
The official answer I got regarding these problems in FN Launchpad Support is:
The only supported method for orientation on MeeGo 1.2 Harmattan is through QtQuick.
That said, there is a workaround in the form of embedding QWidget based UIs in QML through the QGraphicsProxyWidget class. To achieve this, you need to create a wrapper QML project with Window {} or PageStackWindow {} elements, and put your UI in it as a QML element. Note that using this workaround has known issues with layouting, performance and no system specific styling will be applied to the QWidgets used this way. For an example how to do this, see
http://doc.qt.nokia.com/4.7-snapshot/declarative-cppextensions-qwidgets.html
(The example uses a QPushButton, but you could use any QWidget based class). Let me know if you need additional help with this.