【问题标题】:How to change style in PyQt5如何在 PyQt5 中更改样式
【发布时间】:2017-01-05 04:31:06
【问题描述】:

我正在使用 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/

谢谢!

【问题讨论】:

    标签: pyqt styles qt5


    【解决方案1】:

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

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

    编辑:

    here you find the qstyleplugin

    内含6个附加样式,需自行编译

    1. 编辑:

    在 ubuntu 16.04、python3.5 上,我通过将 styleplugins 安装到 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,并在输出中查找缺少的依赖项。

    现在可以使用以下样式:

    ['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
    

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

    【讨论】:

    • 谢谢!很奇怪,我也有 ubuntu 16.04 和 Qt5,我只得到 ['Windows', 'Fusion']。如何添加/创建更多?
    • 如何安装?
    • 我收到此错误 NameError: name 'QStyleFactory' is not defined
    • from PyQt5.QtWidgets import QStyleFactory
    猜你喜欢
    • 2022-01-21
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 2020-10-11
    • 1970-01-01
    • 2011-11-11
    相关资源
    最近更新 更多