gpt4 book ai didi

pyqt - 如何在 PyQt5 中更改样式

转载 作者:行者123 更新时间:2023-12-04 18:30:44 24 4
gpt4 key购买 nike

我正在使用 PyQt 编写 Qt5 应用程序。
我想了解如何更改整个应用程序的样式。
旧的 Qt4 调用如下:

app = QApplication(sys.argv)
app.setStyle(QStyleFactory.create('Cleanlooks'))
和建议的方法 here什么也没做。
它们被弃用了吗?
https://blog.qt.io/blog/2012/10/30/cleaning-up-styles-in-qt5-and-adding-fusion/
谢谢!

最佳答案

可能是 Cleanlooks在您的系统上不再可用。来自 QStyleFactory.keys()您可以询问系统上的可用样式。在 Ubuntu 16.04 和 pyqt5 上,我只得到:

['Windows', 'GTK+', 'Fusion']

编辑:

here you find the qstyleplugin

包含6种附加样式,您必须自己编译
  • 编辑:

  • 在 ubuntu 16.04 和 python3.5 上,我通过将样式插件安装到 QT5 并针对此 QT5 从源代码编译 pyqt5 使其工作:

    通过在线安装程序安装 QT 5.7

    在安装目录中搜索 qmake ,就我而言 /opt/Qt/5.7/gcc_64/bin/qmake
    将qtstyleplugin下载到任意目录 git clone https://code.qt.io/qt/qtstyleplugins.git并安装它:
    cd qtstyleplugins
    /opt/Qt/5.7/gcc_64/bin/qmake # the qmake from the fresh installation
    make
    make install

    现在在 /opt/Qt/5.7/gcc_64/plugins/ 中有一个文件夹“styles”包含其他样式。

    download sip-source ,编译安装

    download pyqt5-source ,编译安装,步骤 python3 configure.py--qmake 提供 QT5-Installation 中的 qmake -option 并在输出中查找缺少的依赖项。

    现在可以使用以下样式:
    ['bb10dark', 'bb10bright', 'cleanlooks', 'cde', 'motif', 'plastique', 'Windows', 'Fusion']

    我有一个 sip 错误:
    RuntimeError: the sip module implements API v11.0 to v11.2 but the PyQt5.QtCore module requires API v11.3

    为了防止它,运行 sudo apt-get purge python3-sip安装 sip 前 as described here

    关于pyqt - 如何在 PyQt5 中更改样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39201227/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com