Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [solved] get orientation within custom component on Harmattan

    QML and Qt Quick
    1
    2
    1314
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      deimos last edited by

      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

      1 Reply Last reply Reply Quote 0
      • D
        deimos last edited by

        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;
        }@

        1 Reply Last reply Reply Quote 0
        • First post
          Last post