linuxqtqt5ubuntu-16.04framebuffer

How to rotate a Qt5 application using the linux framebuffer?


I have an embedded linux application running directly on the linux framebuffer (no x-Windows). We now have to physically rotate the display 180 degrees. How do I get my Qt application to rotate so it doesn't appear upside down? I saw reference to using the following option:

 -platform linuxfb:fb=/dev/fb0:rotation:180 

However, the rotation option seems to be ignored.

Using Qt 5.9.2 on Ubuntu server 16.04.6


Solution

  • You could handle it on application level. With QML thats easy, but with QWidgets the best I could come up with is to render the Widget on a QGraphicsScene and rotate it like this:

    #include "mainwindow.h"
    #include <QApplication>
    
    #include <QGraphicsScene>
    #include <QGraphicsView>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
    
        QGraphicsScene *scene = new QGraphicsScene();
        QGraphicsView *view = new QGraphicsView();
        view->setGeometry(w.geometry());
        view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        scene->addWidget(&w);
        view->setScene(scene);
        view->show();
        view->rotate(180);
    
        //w.show();
    
        return a.exec();
    }
    

    It seems a bit glitchy, but you could give it a try.

    Also I think the correct syntax is -platform linuxfb:fb=/dev/fb0:rotation=180 note the = instead of : Edit: but that did not make a difference for me either.