问题描述
当我自己从源代码交叉编译 Qt 5.8.0 并使用它来构建来自
需要研究的一件事是 QWindowsVistaStyle
类.我注意到当我在 MSYS2 中编译我的程序时,我必须添加 -luxtheme
,因为该类从那里引用了一些函数,例如 GetThemeColor
.这些功能仅在 Windows Vista 及更高版本中可用.当我在 Linux 上使用我自己的 Qt 进行交叉编译时,我不需要那个库,所以也许这个类在我的构建中以某种方式被禁用了.
交叉编译的 Qt 构建细节
我使用 8345 构建了交叉编译的 Qt 和看起来很旧的动态布局示例a> 我的 nixcrpkgs 存储库.如果您查看该提交中的代码,它将准确地向您显示构建 mingw-w64 交叉编译器、构建 Qt 和构建 Qt 示例(包括动态布局)所运行的命令.如果你安装了 Nix,你可以自己构建它,下载 nixcrkpkgs,然后在nixcrpkgs目录下运行nix-build -A pkgs.i686-w64-mingw32.qt.base-examples
.您可以在 Qt 包中查看 我的构建配方一>.
MSYS2 构建细节
我在 MSYS2 的 MINGW64 shell 中运行 这个脚本来构建示例并获得了不错的结果.它依赖于 MSYS2 的 mingw-w64-x86_64-qt5-static 包.您可以查看该包的构建配方.
如果您查看 Qt 5.8.0 中的 src/widgets/configure.json
文件,您可以看到它检查uxtheme.h
的存在,而uxtheme.h
是编译windowsxp
风格的前提,是编译windowsxp
风格的前提代码>windowsvista 样式.通过查看 Qt 的 config.log
,我看到 uxtheme.h
测试失败.我不知道为什么,但这可能是因为 uxtheme.h
不能单独包含;您需要事先包含 windows.h
.我在配置 Qt 后通过查看 src/widgets/qtwidgets-config.pri
文件验证了 windowsxp
和 windowsvista
样式确实没有启用.它有一个要编译的样式列表,windowsvista
不是列表.
我尝试将 -style-windowsxp -style-windowsvista
选项添加到 Qt 的配置命令中,但这些选项只会导致错误,因为 uxtheme.h
测试失败并且这是编译这些主题的先决条件.
我的解决方案是将此补丁应用到 Qt 5.8.0 以完全跳过 uxtheme
测试:
diff -ur qt58-orig/src/widgets/configure.json qt58/src/widgets/configure.json--- qt58-orig/src/widgets/configure.json 2017-05-28 02:07:07.625626151 -0700+++ qt58/src/widgets/configure.json 2017-06-27 21:25:52.752628339 -0700@@ -28,11 +28,6 @@},测试":{- uxtheme":{-标签":uxtheme.h",- 类型":文件",-文件":[uxtheme.h"]- }},特征": {@@ -57,7 +52,7 @@},风格windowsxp":{"label": "WindowsXP",- "条件": "features.style-windows && config.win32 && !config.winrt && tests.uxtheme",+ "条件": "features.style-windows && config.win32 && !config.winrt",输出":[样式"]},风格windowsvista":{
我不知道为什么 MSYS2 包运行良好,因为我在他们的构建脚本中没有看到任何这样的补丁.
When I cross-compile Qt 5.8.0 from source myself and use it to build the Qt "Dynamic Layouts" example from Qt Widgets for Microsoft Windows, it looks old-fashioned, as if it were running on Windows 2000, as shown in the left window below. However, if I compile the exact same program using the pre-built mingw-w64-x86_64-qt5-static package (version 5.8.0-1) from MSYS2, it looks like a nice modern Windows application, as shown in the right window below. How can I fix my version of Qt so that GUIs built with it will look nice? Is there a configuration option I am missing?
One thing to look into is the QWindowsVistaStyle
class. I noticed that when I compiled my program in MSYS2, I had to add -luxtheme
because that class referred to some functions from there, like GetThemeColor
. Those functions are only available in Windows Vista and later. When I cross-compiled using my own Qt on Linux, I didn't need that library, so perhaps that class was somehow disabled in my build.
Cross-compiled Qt build details
I built the cross-compiled Qt and the old-looking Dynamic Layouts example using commit f51d834 of my nixcrpkgs repository. If you look at the code in that commit, it will show you exactly what commands were run to build the mingw-w64 cross-compiler, and build Qt, and build the Qt examples, including Dynamic Layouts. You can build it yourself if you install Nix, download nixcrkpkgs, and then run nix-build -A pkgs.i686-w64-mingw32.qt.base-examples
in the nixcrpkgs directory. You can see my build recipe for the Qt package in that commit.
MSYS2 build details
I ran this script in a MINGW64 shell in MSYS2 to build the example and got good results. It relies on the mingw-w64-x86_64-qt5-static package from MSYS2. You can see the build recipe for that package.
If you look in the src/widgets/configure.json
file from Qt 5.8.0, you can see that it checks for the existence of uxtheme.h
, and that uxtheme.h
is a precondition for compiling the windowsxp
style, which is a precondition for compiling the windowsvista
style. By looking in Qt's config.log
, I saw that the uxtheme.h
test failed. I am not sure why, but it's probably because uxtheme.h
cannot be included on its own; you need to include windows.h
beforehand. I verified that the windowsxp
and windowsvista
styles were indeed not enabled by looking in the src/widgets/qtwidgets-config.pri
file after configuring Qt. It has a list of styles that are going to get compiled, and windowsvista
is not the list.
I tried adding the -style-windowsxp -style-windowsvista
options to Qt's configure command, but those options just cause errors because the uxtheme.h
test is failing and it is a prerequisite for compiling those themes.
My solution was to apply this patch to Qt 5.8.0 to skip the uxtheme
test altogether:
diff -ur qt58-orig/src/widgets/configure.json qt58/src/widgets/configure.json
--- qt58-orig/src/widgets/configure.json 2017-05-28 02:07:07.625626151 -0700
+++ qt58/src/widgets/configure.json 2017-06-27 21:25:52.752628339 -0700
@@ -28,11 +28,6 @@
},
"tests": {
- "uxtheme": {
- "label": "uxtheme.h",
- "type": "files",
- "files": [ "uxtheme.h" ]
- }
},
"features": {
@@ -57,7 +52,7 @@
},
"style-windowsxp": {
"label": "WindowsXP",
- "condition": "features.style-windows && config.win32 && !config.winrt && tests.uxtheme",
+ "condition": "features.style-windows && config.win32 && !config.winrt",
"output": [ "styles" ]
},
"style-windowsvista": {
I'm not sure why the MSYS2 package worked well, since I don't see any patch like this in their build script.
这篇关于Qt GUI 主题看起来很老式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!