Skip to content

Zchydem's Blog

#Qt, #Linux, #Programming, #MeeGo…

Archive

Tag: “Orientation Change”

One of the greatest thing in Qt has always been a sophisticated layout management. There are actually two different layout systems in Qt: a layout management for QWidget based widgets and a layout management for QGraphicsWidget based widgets. This article will focus on the latter one, but the basic idea in both layout management systems is similar – the application developer doesn’t need to hardcode widget’s size and position in relative its parent, all this is done automatically by the Qt. Qt also tries to fill in all the available space so for example when resizing the application window, the layout always fills the free space (I know this can be prevented also). At this point if you are not familiar of Qt’s layout management it is worth to spend some time with reading documentation  from here.

continue reading…

Couple days ago I posted a video example of the MVC-model running on N900. Someone asked me that how did I do that thing and I believe that the question was about how to react on orientation changes in Qt application on N900. If you are not familiar with Qt D-Bus Module it’s worth to read the documentation from here first.

The orientation changes in N900 can be listened through a dbus interface. Doing that is pretty straight forward and it requires only couple lines of code:

QDBusConnection systemBus = QDBusConnection::systemBus();
systemBus.connect(“com.nokia.mce”,
“/com/nokia/mce/signal”,
“com.nokia.mce.signal”,
“sig_device_orientation_ind”,
&scene, SLOT(orientationChanged(QString)));
    MyReceiverClass * receiver = new MyReceiverClass(this);
    QDBusConnection systemBus = QDBusConnection::systemBus();
    systemBus.connect("com.nokia.mce",
                      "/com/nokia/mce/signal",
                      "com.nokia.mce.signal",
                      "sig_device_orientation_ind",
                      receiver, SLOT(orientationChanged(QString)));

In the code snipplet above I have a basic QObject based class “MyReceiverClass” which have a slot called “orientationChanged(QString)”. This slot takes a QString as an argument. When a signal called “sig_device_orientation_ind” has been send via D-Bus, the receiver’s slot will be called automatically and it can have one of the  ”landscape” or “portrait” strings as a literal value. The rest of is up to the developer to decide what to do in the slot.

That’s it. Simple, isn’t it?