在arm上进行Qt图形界面开发不可避免的一个问题就是屏幕的默认显示横屏竖屏和我们需要的显示方向不一致的问题。
Qt4的解决方案
Qt4具有官方的支持,在Qt4中在编译源码的时候添加编译选项
-qt-gfx-transformed
然后就可以通过设置环境变量来设置屏幕的旋转方向
export QWS_DISPLAY='Transformed:Rot270'
其中参数支持0、 90、 180、 270.
亲测qt4.8.6可用。
Qt5的解决方案
在Qt5中官方移除了Qt4的屏幕旋转属性。有两种方法进行显示的旋转。
1、对页面上设置旋转属性,这样窗口实际没有旋转,只是对显示内容进行了旋转。
2、对源码通过打补丁的方式使得支持旋转。
以下讲解打补丁的方法:
先说一下这个方法的弊端,看完后自行决定是否继续向下看。
使用打补丁的方法带来的弊端是虽然解决了屏幕旋转的问题,但是对触摸的兼容并不好。旋转之后会出现触摸的点和显示的点对应不上的问题。很多帖子说在进行屏幕校准时也旋转相应的角度。我用tslib1.21+qt5.12.2测试后发现无论如何旋转始终不能对应的很好。
如果你对触摸没有要求则可以通过打补丁的方式来进行旋转。以下附上补丁全部内容:
diff --git a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.cpp b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp
index a66c9fa..a5b5f13 100644
--- a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.cpp
+++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp
@@ -290,7 +290,7 @@ static void blankScreen(int fd, bool on)
}
QLinuxFbScreen::QLinuxFbScreen(const QStringList &args)
- : mArgs(args), mFbFd(-1), mBlitter(0)
+ : mArgs(args), mFbFd(-1), mBlitter(0), mRotation(90)
{
}
@@ -316,6 +316,7 @@ bool QLinuxFbScreen::initialize()
QRegularExpression mmSizeRx(QLatin1String("mmsize=(\\d+)x(\\d+)"));
QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)"));
QRegularExpression offsetRx(QLatin1String("offset=(\\d+)x(\\d+)"));
+ QRegularExpression rotationRx(QLatin1String("rotation=(0|90|180|270)"));
QString fbDevice, ttyDevice;
QSize userMmSize;
@@ -337,6 +338,8 @@ bool QLinuxFbScreen::initialize()
ttyDevice = match.captured(1);
else if (arg.contains(fbRx, &match))
fbDevice = match.captured(1);
+ else if (arg.contains(rotationRx, &match))
+ mRotation = match.captured(1).toInt();
}
if (fbDevice.isEmpty()) {
@@ -375,9 +378,17 @@ bool QLinuxFbScreen::initialize()
mDepth = determineDepth(vinfo);
mBytesPerLine = finfo.line_length;
QRect geometry = determineGeometry(vinfo, userGeometry);
+ QRect originalGeometry = geometry;
+ if( mRotation == 90 || mRotation == 270 )
+ {
+ int tmp = geometry.width();
+ geometry.setWidth(geometry.height());
+ geometry.setHeight(tmp);
+ }
+
mGeometry = QRect(QPoint(0, 0), geometry.size());
mFormat = determineFormat(vinfo, mDepth);
- mPhysicalSize = determinePhysicalSize(vinfo, userMmSize, geometry.size());
+ mPhysicalSize = determinePhysicalSize(vinfo, userMmSize, originalGeometry.size());
// mmap the framebuffer
mMmap.size = finfo.smem_len;
@@ -387,11 +398,11 @@ bool QLinuxFbScreen::initialize()
return false;
}
- mMmap.offset = geometry.y() * mBytesPerLine + geometry.x() * mDepth / 8;
+ mMmap.offset = originalGeometry.y() * mBytesPerLine + originalGeometry.x() * mDepth / 8;
mMmap.data = data + mMmap.offset;
QFbScreen::initializeCompositor();
- mFbScreenImage = QImage(mMmap.data, geometry.width(), geometry.height(), mBytesPerLine, mFormat);
+ mFbScreenImage = QImage(mMmap.data, originalGeometry.width(), originalGeometry.height(), mBytesPerLine, mFormat);
QByteArray hideCursorVal = qgetenv("QT_QPA_FB_HIDECURSOR");
#if !defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK)
@@ -436,7 +447,26 @@ QRegion QLinuxFbScreen::doRedraw()
QVector<QRect> rects = touched.rects();
for (int i = 0; i < rects.size(); i++)
+ {
+ if( mRotation == 90 || mRotation == 270 )
+ {
+ mBlitter->translate(mGeometry.height()/2, mGeometry.width()/2);
+ }
+ else if( mRotation == 180 )
+ {
+ mBlitter->translate(mGeometry.width()/2, mGeometry.height()/2);
+ }
+
+ if( mRotation != 0 )
+ {
+ mBlitter->rotate(mRotation);
+ mBlitter->translate(-mGeometry.width()/2, -mGeometry.height()/2);
+ }
+
mBlitter->drawImage(rects[i], *mScreenImage, rects[i]);
+
+ mBlitter->resetTransform();
+ }
return touched;
}
diff --git a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.h b/src/plugins/platforms/linuxfb/qlinuxfbscreen.h
index 1997d46..a34414f 100644
--- a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.h
+++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.h
@@ -57,6 +57,7 @@ private:
QStringList mArgs;
int mFbFd;
int mTtyFd;
+ int mRotation;
QImage mFbScreenImage;
int mBytesPerLine;

798

被折叠的 条评论
为什么被折叠?



