Important: Please read the Qt Code of Conduct -

Rotating Screen on Embedded Device touchscreen (nativeOrientation != desired) and resulting issues

  • Hi everyone,

    I want to rotate my Qt Application (Main- and sub-widgets) to my desired landscape orientation (touch display is actually portrait). Note: I used the existing demo application for a usb-cam and I don't have any window management. Using qt 5.4.2

    I managed to rotate the application using a graphicsview (with set opengl widget) and graphicscene (adding the main-widget).
    Some issues I have:

    • Sub-menus of the main menubar don't appear next to the submenu entry, e.g., Focus->SetAuto or ->SetManual In this case this sub-menubox appears at the bottom of the rotated scene. Without any view/scene it works fine.
    • Using the menubars with the touchscreen seems to be broken. Originally I could do a little on the menubars using the ts, now it does not do anything (but at least I removed the bug that the menubar hangs when clicking on the specific submenu (had no parent))

    All menus didn't look like something special: Just actions for clicking it are assigned. One of them in questions adds dynamic menus. But another that crashes the menu is just fixed as the others. It looks like some of theses menus appear just a short time in front/back of the parent menu...

    • The video image is rendered using an OpenGL Widget as a sub-widget of the main-widget (not supported by graphicsscene), I had to switch to an standard widget without OpenGL

    • Non important issue but: The click/touch events are put through accordingly, but the mouse movement (with an attached mouse) and rendering is still in portrait mode.

    Any guesses for causes or where I might have a look into for solving these issues?

    Thanks in advance

    BR, Schakal

  • Here is an example to replicate the positioning problem of the menus when rotating from portrait to landscape.

    #include <QApplication>
    #include <QGraphicsScene>
    #include <QGraphicsView>
    #include <QGraphicsProxyWidget>
    #include <QTransform>
    #include <QScreen>
    #include <QOpenGLWidget>
    #include <QMenu>
    #include <QMenuBar>
    #include <QAction>
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        QGraphicsView view;
        QTransform transform;
        QGraphicsScene scene;
        QScreen *ps = QApplication::primaryScreen();
        QGraphicsProxyWidget  *proxy;
        Qt::ScreenOrientation pso;
        QSize dSize(ps->size());
        if((pso = ps->orientation()) != Qt::LandscapeOrientation )
          //Swap dimensions if height is larger than width
        view.setViewport(new QOpenGLWidget);
        QMainWindow *test = new QMainWindow;
        proxy = scene.addWidget(test);
        QString tmpString = QObject::tr("File");
        //Providing menu bar is really necessary (otherwise even the fileMenu is not positioned correctly)
        QMenu *fileMenu = new QMenu(tmpString,test->menuBar());
        tmpString = QObject::tr("Recently");
        QMenu *fileSubMenu = new QMenu(tmpString,fileMenu);
        tmpString = QObject::tr("blubb");
        fileMenu->addAction(new QAction(tmpString,test));
        tmpString = QObject::tr("blubb2");
        fileSubMenu->addAction(new QAction(tmpString,test));
        tmpString = QObject::tr("blubb3");
        fileSubMenu->addAction(new QAction(tmpString,test));;
        return a.exec();

Log in to reply