代码之家  ›  专栏  ›  技术社区  ›  jpyams David Thompson

在PyQt4中修改系统样式

  •  0
  • jpyams David Thompson  · 技术社区  · 7 年前

    我试图使启用了三态的QtCheckBox在其状态为部分时在复选框中绘制一个X。我现在让Qt处理样式,使其与操作系统匹配,我希望保持这种方式,只更改复选框的绘制方式。

    >>> app = QtGui.QApplication()
    >>> type(app.style())
    PyQt4.QtGui.QCommonStyle
    

    但是当我试着跑步的时候 app.setStyle(QtGui.QCommonStyle()) ,GUI更改,最明显的是复选标记从 QCheckBox

    QCommonStyle ,并基于文档,仅绘制所有样式通用的元素。

    所以我有两个问题:

    1. 为什么是 type(app.style()) 返回 Q常见风格 ?

    我正在使用PyQt4。

    1 回复  |  直到 7 年前
        1
  •  2
  •   eyllanesc Yonghwan Shin    7 年前

    为什么类型(app.style())返回QCommonStyle,当它看起来是

    类似于style的类通常继承QCommonStyle,例如在我的例子中,我有以下样式:

    for key in QtGui.QStyleFactory.keys():
        st = QtGui.QStyleFactory.create(key)
        print(key, st.metaObject().className(), type(app.style()))
    

    Adwaita-Dark Adwaita::Style   <class 'PyQt4.QtGui.QCommonStyle'>
    Adwaita      Adwaita::Style   <class 'PyQt4.QtGui.QCommonStyle'>
    Breeze       Breeze::Style    <class 'PyQt4.QtGui.QCommonStyle'>
    bb10dark     QBB10DarkStyle   <class 'PyQt4.QtGui.QCommonStyle'>
    bb10bright   QBB10BrightStyle <class 'PyQt4.QtGui.QCommonStyle'>
    cleanlooks   QCleanlooksStyle <class 'PyQt4.QtGui.QCommonStyle'>
    gtk2         QGtkStyle        <class 'PyQt4.QtGui.QCommonStyle'>
    cde          QCDEStyle        <class 'PyQt4.QtGui.QCommonStyle'>
    motif        QMotifStyle      <class 'PyQt4.QtGui.QCommonStyle'>
    plastique    QPlastiqueStyle  <class 'PyQt4.QtGui.QCommonStyle'>
    qt5ct-style  Qt5CTProxyStyle  <class 'PyQt4.QtGui.QCommonStyle'>
    QtCurve      QtCurve::Style   <class 'PyQt4.QtGui.QCommonStyle'>
    Windows      QWindowsStyle    <class 'PyQt4.QtGui.QCommonStyle'>
    Fusion       QFusionStyle     <class 'PyQt4.QtGui.QCommonStyle'>
    

    正如我们所观察到的,所有人都是这种类型的。

    我实际上如何获得Qt使用的样式?

    上一部分已经回答了这个问题:

    print(QtGui.QApplication.style().metaObject().className())
    

    就我而言:

    Adwaita::Style