Qt 5 embedded screen rotation



  • With Qt4 application rotation of 90, 180 and 270 degree was fairly easy with -qws -display transformed:Rot270.

    I've been trying to find the equivalent with Qt 5 with Ogles2/eglfs, starting the application with -platform eglfs command line.
    I'm starting to dig through the source and will post an answer if I find it. I'm hoping post the question here will result in a quicker and hopefully more correct solution.
    Anyone know the Qt5 equivalent to -qws -display transformed:Rot270?

    thanks



  • Now,I have the same problem too.

    Someone can teach me?

    thanks a lot.



  • Does anyone know how to rotate screens on QT5 embedded ?



  • I am looking for this solution as well.
    Any help would be appreciated!



  • I would also be interested in a general solution.

    If you are using qml then you can rotate any root items just by inserting the following. This will rotate all children and even handle touch input correctly.
    @
    transform: Rotation {
    angle: 180
    origin.x: root.width / 2
    origin.y: root.height / 2
    }
    @



  • Thanks for JoelC.

    But I use Qt Widgets Application.

    Any help would be appreciated!



  • I also have this problem. We are porting a c++/qml application from qt4.8 to qt5. We have used transformed:Rot90 and it has worked fine without any performance issues. However if we perform the following in our qml code:

    @
    transform: Rotation {
    angle: 90
    }
    @

    the qml part becomes laggy.

    Has someone come up with a solution to this?



  • Dear All,

    Just one more information that i want to add this is that if you don't want to pass

    @-platform eglfs@

    the above argument while running your app each time, you can simply store this information in the environment variable :

    @export QT_QPA_PLATFORM=eglfs@

    And now you can directly run your app without passing any argument.

    Cheers!!



  • Same problem here. Any information is welcome, even it is a statement that this is not possible.

    Btw: is this the wrong use case? Should one use QML?



  • There is no equivalent of QWS' transforms, neither in linuxfb nor eglfs.

    Qt Quick applications are expected to do the transformations themselves.

    For widget apps this is a bit unfortunate since they are left out in the cold for now. :/





  • Hello All,
    I have same problem. App works fine on Qt4 with QML 1.1 version on both landscape and portrait mode... I use transformed:Rot270.

    But in Qt5 if I try to rotate my app in QML rootitem by transform: Rotation {
    angle: 180
    origin.x: root.width / 2
    origin.y: root.height / 2
    }

    it does not work properly...only part of the screen is rotated..Any known issues in that area ?
    Thanks Kumars



  • My solution was: (in mainwindow.cpp-constructor):

    QGraphicsScene *scene = new QGraphicsScene();
    QGraphicsView *view = new QGraphicsView(parent);
    view->setGeometry(0,0,X,Y); // actual Display size
    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    QGraphicsProxyWidget *proxy = scene->addWidget(this);
    view->setScene(scene);
    view->show();
    view->rotate(90);


  • @agocs Does this mean that one cannot run a QWidget based application in portrait mode on a natively landscape display? For example, I have a 480x272 display that my hardware team wants to orient in a portrait orientation.

    I have tried a number of things including the last suggestion on this thread from 0xFa81 but i end up with garbled text. That's the best way i can explain it. When I run the same code on my development box it works fine and the text is not garbled and show up sideways on my monitor. But if i run it on my embedded device i get text where the letters are switched around.

    I started another thread about this here:

    http://forum.qt.io/topic/55907/qwidget-based-application-in-non-native-orientation-on-embedded-linux-with-fbdev-platform



  • Hi,

    Does Qt rotation is done as part of Qt library/application or as control to framebuffer (which in this case is expected to support rotation).
    I ask because in our HW/fbdev driver there is no support for rotation, so I wander if Qt can do this rotation in software...

    Thanks,
    Ran



  • @0xFa81 I'm curious if this is the method you are still using.

    I'm using this on a product I'm helping with, and the performance is rather slow and is negatively impacting product design requirements (graphing updates per second).

    I've tried adjusting the QGraphicsView settings (optimization, etc), but no improvement.

    If anyone has found a better way to rotate a landscape LCD to portrait, on a platform using linuxFB (all software driven, no hardware graphics cores at all) help is appreciated.

    This platform was previously being developed in Qt4, and the QWS system rotated without any noticeable issues...

    Thank you!

    Matthew



  • Are there any news about rotating the Display? I do have a Raspberry 7" Display which is landscape native. Using lcd_rotate in the boot config doesnt work (it only works for 180°) and display_rotate misses to rotate the touchscreen. So I need to either rotate the whole thing (touch and display) or just the touchscreen (then I would use the display_rotate). Is there a way to do this?

    export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=rotate=90

    somehow doesnt work for me (should it?)

    thanks!



  • Though it is a pretty old query, I think answering to this thread is still valid.
    The major difference between Qt4.8 and Qt5.x.x is that, they removed the Qt's own windowing system and let it open for user defined windowing system. That means, QWS (Qt Windowing System) is no more part of the Qt and we can use X11, Wayland or FB as the backend for the same.
    If someone want to rotate the screen, then basically that is doing with the help of the windowing system but not just with the Qt itself. As many other people stated, Qt4 rotation is done with the QWS.
    If you are using X11 windowing system along with Qt5, then X11 have rotation feature and one should make use of that for the Qt rotation.
    I hope this helps.

    Regards,
    Ajith P V



  • Hi, Is this also valid for the QT embedded since it is using EGLFS? All I found was the workaround using setTransformation, but this (at least thats what it looks like) was removed in QT 5.



  • @tsaG Yes, you are right. "setTransformation" is part of QWSDisplay and in Qt5, they have removed the complete QWS windowing system itself. So as far as my knowledge, there is no equivalent for "setTransformation". However, instead of QWS windowing system, now Qt5 opens to any other popular windows systems such as x11 which can do this trick.
    PS: I'm afraid I can't help you with EGLFS since, my qt work is around the corner of X11 almost all time.



  • @tsaG There does not seem to be any easy way – unless you are using QML.

    However, it is possible that your platform supports rotation. For example, Raspberry Pi (kind of) supports rotation as a boot-up option. The rotation occurs then at a lower level (i.e. below the OpenGL layer). Other embedded platforms may provide similar functionality.

    I actually tested both methods (with RPi/EGLFS). Using the QML rotation is relatively fast, at least I did not notice any significant speed difference between landscape and portrait orientations. Using the platform-specific rotation was slow, but that result cannot be generalized to other platforms. (RPi seems to fall into some sort of soft OpenGL when rotated by 90° or 270°.)

    Of course, X11 or Wayland may provide a solution here, but at the same time the performance will suffer both at startup and during run time. YMMV.

    This is a strange omission indeed, as screen rotation is not uncommon with embedded devices.



  • I found a solution that works for single touch. First I rotate the display:

    sudo nano /boot/config.txt
    

    Add this at the end for a 90 degree rotation:

    display_rotate=1
    

    Restart unit.

    Then I Just catch the touch event, transforms the coordinate and then send a mouse event instead.

    Creating a new class:

    myguiapplication.h

    #ifndef MYGUIAPPLICATION_H
    #define MYGUIAPPLICATION_H
    
    #include <QGuiApplication>
    #include <QEvent>
    
    class MyGuiApplication : public QGuiApplication
    {
        Q_OBJECT
    public:
        MyGuiApplication(int &argc, char **argv);
        virtual bool notify(QObject*, QEvent*);
    };
    
    #endif // MYGUIAPPLICATION_H
    

    myguiapplication.c

    #include "myguiapplication.h"
    #include <QTouchEvent>
    #include <QMouseEvent>
    #include <QDebug>
    
    MyGuiApplication::MyGuiApplication(int &argc, char **argv) : QGuiApplication(argc, argv)
    {
    
    }
    
    bool MyGuiApplication::notify(QObject* target, QEvent* event)
    {
        try {
            switch (event->type())
            {
            case QEvent::TouchBegin:
            case QEvent::TouchUpdate:
            case QEvent::TouchEnd:
            {
                QTouchEvent* te = static_cast<QTouchEvent*>(event);
    
                if (te->device()->type() == QTouchDevice::TouchScreen)
                {
                    QList<QTouchEvent::TouchPoint> tps = te->touchPoints();
    
                    if(tps.count() != 1)
                    {
                        qDebug() << "Touch points != 1";
                        return true;
                    }
    
                    qreal tx = tps.first().pos().x();
                    qreal ty = tps.first().pos().y();
    
                    qreal mx = 480.0/800 * ty;
                    qreal my = 800 - 800.0/480 * tx;
    
                    qDebug() << tx << "," << ty << " => " << mx << "," << my;
    
                    QPointF mp(mx, my);
    
                    switch (event->type())
                    {
                    case QEvent::TouchBegin:
                    {
                        qDebug() << "BEGIN";
                        QMouseEvent ee(QEvent::MouseButtonPress, mp, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                        QCoreApplication::sendEvent(target, &ee);
                        break;
                    }
                    case QEvent::TouchUpdate:
                    {
                        qDebug() << "UPDATE";
                        QMouseEvent ee(QEvent::MouseMove, mp, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                        QCoreApplication::sendEvent(target, &ee);
                        break;
                    }
                    case QEvent::TouchEnd:
                    {
                        qDebug() << "END";
                        QMouseEvent ee(QEvent::MouseButtonRelease, mp, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                        QCoreApplication::sendEvent(target, &ee);
                        break;
                    }
                    default:
                        qDebug() << "Unhandled touch event";
                        return true;
                    }
    
                    return true;
                }
                break;
            }
            case QEvent::MouseButtonPress:
            {
                QMouseEvent *k = (QMouseEvent *)event;
                qDebug() << "MouseButtonPress:" << k->pos();
                break;
            }
            case QEvent::MouseMove:
            {
                QMouseEvent *k = (QMouseEvent *)event;
                qDebug() << "MouseMove:" << k->pos();
                break;
            }
            case QEvent::MouseButtonRelease:
            {
                QMouseEvent *k = (QMouseEvent *)event;
                qDebug() << "MouseButtonRelease:" << k->pos();
                break;
            }
            default:
                ;
            }
        } catch (...) {
        }
    
        return QGuiApplication::notify(target, event);
     }
    

    And then using my new class instead of QGuiApplication:

    #include "myguiapplication.h"
    #include <QQmlApplicationEngine>
    #include <QQmlContext>
    int main(int argc, char *argv[])
    {
        MyGuiApplication app(argc, argv);
        //...
    }
    


  • Has anyone found a suitable solution for an embedded device on eglfs? I want to use a natively portrait display in landscape orientation, for displaying Qt5 Widget applications


Log in to reply
 

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