如何在Qt5qt中更改样式

时间:2016-08-29 07:59:06

标签: pyqt styles qt5

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

谢谢!

1 个答案:

答案 0 :(得分:6)

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

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

编辑:

here you find the qstyleplugin

包含6个其他样式,你必须自己编译

  1. 编辑:
  2. 在ubuntu 16.04上,python3.5我通过将样式插件安装到QT5并从源代码编译pyqt5来实现这个QT5:

    通过onlineinstaller安装QT 5.7

    在installationdirectory中搜索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/中有一个包含其他样式的“样式”文件夹。

    download sip-source,编译并安装

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

    现在可以使用以下样式:

    ['bb10dark', 'bb10bright', 'cleanlooks', 'cde', 'motif', 'plastique', 'Windows', 'Fusion']
    

    我得了一个sip-error:

    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