Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Lock screen orientation with Qt
Forum Updated to NodeBB v4.3 + New Features

Lock screen orientation with Qt

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 6 Posters 8.4k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cheng
    wrote on last edited by
    #1

    How to lock screen orientation with Qt code? I have seen the code from native symbian c++ that run on Qt, but it is not work for me.

    Code:
    @
    //example_application.pro

      symbian: {
    
          LIBS += -lcone -leikcore -lavkon
    
      }
    

    //example_application.cpp

      #ifdef Q_OS_SYMBIAN
    
      #include <eikenv.h>
    
      #include <eikappui.h>
    
      #include <aknenv.h>
    
      #include <aknappui.h>
    
      #endif
    
    
      CAknAppUi* appUi = dynamic_cast (CEikonEnv::Static()->AppUi());
    
      TRAPD(error,
    
      if (appUi) appUi->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape);
    
      );
    

    @
    I am using Qt Creator from NokiaQtSDK.

    1 Reply Last reply
    0
    • kkoehneK Offline
      kkoehneK Offline
      kkoehne
      Moderators
      wrote on last edited by
      #2

      I have by chance an example project open that also does this. The only difference I can instanly spot is that it also links against the eiksrv library:

      LIBS += -leiksrv

      Director R&D, The Qt Company

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kamalakshantv
        wrote on last edited by
        #3

        try this

        @#ifdef Q_OS_SYMBIAN

        CAknAppUi* appUi = dynamic_cast<CAknAppUi*>( CEikonEnv::Static()->AppUi() );
          
        if(appUi) 
          {
          TRAP_IGNORE( appUi->SetOrientationL( CAknAppUi::EAppUiOrientationLandscape ) );
          }
        

        #endif // Q_OS_SYMBIAN@

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mismail
          wrote on last edited by
          #4

          I used this code but it did not work for me.
          I built my app using QML and C++.
          @QApplication::setGraphicsSystem("raster");
          QApplication app(argc, argv);
          #ifdef Q_OS_SYMBIAN
          CAknAppUi* appUi = dynamic_cast<CAknAppUi*>( CEikonEnv::Static()->AppUi() );
          if(appUi)
          {
          appUi->SetOrientationL( CAknAppUi::EAppUiOrientationPortrait);
          }
          #endif // Q_OS_SYMBIAN
          QmlApplicationViewer viewer;
          //viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);@

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kamalakshantv
            wrote on last edited by
            #5

            [quote author="mismael" date="1307435986"]I used this code but it did not work.[/quote]

            You might have missed something. The new Qt Creator template creates sample app project with orientation lock code in it. Try with that once.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thisisbhaskar
              wrote on last edited by
              #6

              On your main QWidget or QMainWindow or QGraphicsView call function

              @setAttribute(Qt::WA_LockPortraitOrientation, true);@

              This works in all the platforms.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                thisisbhaskar
                wrote on last edited by
                #7

                For Qml, Atleast below code works well for me

                @QmlApplicationViewer viewer;
                viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
                viewer.setResizeMode(QDeclarativeView::SizeRootObjectToView);
                viewer.showFullScreen();@
                

                This locks my screen orientation of portrait.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Chuck Gao
                  wrote on last edited by
                  #8

                  In my memory, if you create a qml project(for mobile) in the Qt Creator, it will generate these code to you :)

                  some snap code:

                  @void MainWindow::setOrientation(ScreenOrientation orientation)
                  {
                  #ifdef Q_OS_SYMBIAN
                  if (orientation != ScreenOrientationAuto) {
                  #if defined(ORIENTATIONLOCK)
                  const CAknAppUiBase::TAppUiOrientation uiOrientation =
                  (orientation == ScreenOrientationLockPortrait) ? CAknAppUi::EAppUiOrientationPortrait
                  : CAknAppUi::EAppUiOrientationLandscape;
                  CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
                  TRAPD(error,
                  if (appUi)
                  appUi->SetOrientationL(uiOrientation);
                  );
                  Q_UNUSED(error)
                  #else // ORIENTATIONLOCK
                  qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation.");
                  #endif // ORIENTATIONLOCK
                  }
                  #elif defined(Q_WS_MAEMO_5)
                  Qt::WidgetAttribute attribute;
                  switch (orientation) {
                  case ScreenOrientationLockPortrait:
                  attribute = Qt::WA_Maemo5PortraitOrientation;
                  break;
                  case ScreenOrientationLockLandscape:
                  attribute = Qt::WA_Maemo5LandscapeOrientation;
                  break;
                  case ScreenOrientationAuto:
                  default:
                  attribute = Qt::WA_Maemo5AutoOrientation;
                  break;
                  }
                  setAttribute(attribute, true);
                  #else // Q_OS_SYMBIAN
                  Q_UNUSED(orientation);
                  #endif // Q_OS_SYMBIAN
                  }

                  void MainWindow::showExpanded()
                  {
                  #ifdef Q_OS_SYMBIAN
                  showFullScreen();
                  #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
                  showMaximized();
                  #else
                  show();
                  #endif
                  }@

                  Chuck

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved