[solved] get orientation within custom component on Harmattan



  • Hi,

    I am trying to get desktop size or orientation from a custom item. No problems in qml, but I need to know it within the custom component.
    Both this two methods always return 854x480 even if in portrait:

    @QApplication::desktop()->width();
    QApplication::desktop()->height();@

    @XWindowAttributes attributes;
    XGetWindowAttributes(QX11Info::display(), QX11Info::appRootWindow(), &attributes)
    int w = attributes.width;
    int h = attributes.height;@

    Any hints please ?

    thanks in advance

    Edit: also QSystemDisplayInfo::orientation() always return Portrait



  • I just found a solution querying DBus:

    @int getOrientation()
    {
    int orientation = -1;

    #if !defined(QT_NO_DBUS)
    QDBusMessage reply = QDBusConnection::systemBus().call(
    QDBusMessage::createMethodCall("com.nokia.SensorService", "/org/maemo/contextkit/Screen/TopEdge",
    "org.maemo.contextkit.Property", "Get"));
    if (reply.type() != QDBusMessage::ErrorMessage) {
    QList<QVariant> args;
    qvariant_cast<QDBusArgument>(reply.arguments().at(0)) >> args;
    if (args.count() == 0) {
    return orientation;
    }
    QString nativeOrientation = args.at(0).toString();
    if (nativeOrientation == "top") {
    orientation = 1; // Landscape
    } else if (nativeOrientation == "left") {
    orientation = 2; // Portrait
    } else if (nativeOrientation == "bottom") {
    orientation = 3; // InvertedLandscape
    } else if (nativeOrientation == "right") {
    orientation = 4; // InvertedPortrait
    }
    }
    #endif
    return orientation;
    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.