【问题标题】:Get and set background color of QFrame or QGroupBox with ONLY palette仅使用调色板获取和设置 QFrame 或 QGroupBox 的背景颜色
【发布时间】:2020-03-05 10:25:07
【问题描述】:

如何使用调色板获取和设置QFrameQGroupBox 的背景颜色?据我所知,我可以使用QPalette.ColorRole.Background 来影响它们,但这也会影响窗口颜色,所以不是获得较浅的阴影,而是将整个界面设置为纯色。有没有办法分别影响它们?

我知道我可以使用样式表,但在这种情况下,我只想尽可能使用调色板来实现它。

【问题讨论】:

    标签: python python-2.7 pyside2


    【解决方案1】:

    这样的?

    from PySide import QtWidgets, QtGui
    
    if __name__ == "__main__":
        app = QtWidgets.QApplication([])
    
        frame = QtWidgets.QFrame()
        frame.setFrameShape(QtWidgets.QFrame.Box)
        frame.setLineWidth(3)
        frame.setAutoFillBackground(True)
        palette = frame.palette()
        palette.setBrush(QtGui.QPalette.Background, QtGui.QColor("#ff00ff"))
        frame.setPalette(palette)
    
        widget = QtWidgets.QWidget()
        w_layout = QtWidgets.QVBoxLayout(widget)
        w_layout.addWidget(frame)
    
        widget.resize(200, 200)
        widget.show()
        app.exec_()
    

    【讨论】:

      猜你喜欢
      • 2011-05-16
      • 1970-01-01
      • 2016-10-04
      • 2011-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      相关资源
      最近更新 更多