如何获得和设置调色板的QFrame
和QGroupBox
的背景颜色?据我所知,我可以用QPalette.ColorRole.Background
来实现它们,但这也影响了窗口的颜色,因此整个界面设置为纯色,而不是使用更浅的阴影。有没有办法分别影响它们?
我知道我可以使用样式表,但是在这种情况下,我只想尽可能地使用调色板来实现它。
这样的事情?
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_()