AutoRotate with QDeclarativeView



  • Hi, I'm writing an app combining Qt Quick and Qt, I inherit QDeclarativeView and the app works, but when I rotate the screen my main rectangle doesn't get rotated it keeps beign 800x480 and not 480x800, I copied the code for rotating an app in maemo, am I missing something?

    In main.cpp:

    @wMain.setOrientation(WMain::ScreenOrientationAuto);@

    In WMain.cpp

    @void WMain::setOrientation(ScreenOrientation orientation)
    {
    Qt::WidgetAttribute attribute;
    switch (orientation) {
    #if QT_VERSION < 0x040702
    // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
    case ScreenOrientationLockPortrait:
    attribute = static_castQt::WidgetAttribute(128);
    break;
    case ScreenOrientationLockLandscape:
    attribute = static_castQt::WidgetAttribute(129);
    break;
    default:
    case ScreenOrientationAuto:
    attribute = static_castQt::WidgetAttribute(130);
    break;
    #else // QT_VERSION < 0x040702
    case ScreenOrientationLockPortrait:
    attribute = Qt::WA_LockPortraitOrientation;
    break;
    case ScreenOrientationLockLandscape:
    attribute = Qt::WA_LockLandscapeOrientation;
    break;
    default:
    case ScreenOrientationAuto:
    attribute = Qt::WA_AutoOrientation;
    break;
    #endif // QT_VERSION < 0x040702
    };
    setAttribute(attribute, true);
    }@



  • hi,
    if u r developing Qt Quick app
    in main.cpp file u will find something like this
    @viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);@



  • Thanks but I don't have a QmlApplicationViewer in main.cpp, I show WMain, and in WMain I set my qml source
    @setSource(QUrl("qml/regchecker/main.qml"));@

    So I don't use directly QmlApplicationViewer but instead I inherit from QDeclarativeView



  • How can I get access to QmlApplicationViewer? I want to use it to avoid this error I am getting using tabs with a QApplicationView:
    @
    warning: screen.orientation is deprecated. use screen.currentOrientation and screen.allowedOrientations instead
    @
    Since QmlApplicationViewer extends QApplicationView and not the other way around, I need to use it so that I can set orientation. I tried including QmlApplicationViewer.h, but it said that it did not exist.


Log in to reply
 

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