How to rotate a Qt5 application using the linux framebuffer?

落爺英雄遲暮 提交于 2020-01-03 12:58:41

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/56601993/how-to-rotate-a-qt5-application-using-the-linux-framebuffer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!