首页 > 解决方案 > 从 .app 运行时窗口变得模糊/像素化

问题描述

我制作了一个小 Python 脚本,它在 QtWidget 上运行时钟,一切正常。

我想用它制作一个可执行文件,因此我使用了 pyinstaller 并且从代码的角度来看一切正常。

但是,当我创建一个 .app (macOS)(使用 -w 选项)并使用此应用程序运行脚本时,窗口及其内容的质量会变得更差,就像模糊/像素化一样。奇怪的是,如果我从 .app/Contents/MacOS/ 中提取脚本并从应用程序外部的文件夹中运行它,质量就会再次正常。

看截图:

正常质量

质量差

有谁知道为什么会这样?和/或如何解决?

标签: pythonmacospyqt5pyinstaller

解决方案


在应用程序的 info.plist 文件中将“NSHighResolutionCapable”设置为“True”应该可以解决问题。

<plist version="1.0">
<dict>
    <key>CFBundleDisplayName</key>
    <string>port_poirot</string>
    <key>CFBundleExecutable</key>
    <string>MacOS/port_poirot</string>
    <key>CFBundleIconFile</key>
    <string>detective.icns</string>
    <key>CFBundleIdentifier</key>
    <string>port_poirot</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>port_poirot</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>0.0.0</string>
    <key>NSHighResolutionCapable</key>
    <string>True</string>
</dict>
</plist>

更改 pyinstaller 的规范文件使其更容易一些。请参阅https://pyinstaller.readthedocs.io/en/stable/spec-files.html#spec-file-options-for-a-mac-os-x-bundle


推荐阅读