I want to change the color of the button of a button group object in PyQt5. I tried
QButtonGroup.setStyleSheet(\"\"\"
QButtonGroup
According to Qt doc:
QButtonGroup provides an abstract container into which button widgets can be placed. It does not provide a visual representation of this container (see QGroupBox for a container widget), but instead manages the states of each of the buttons in the group.
Therefore, you cannot set a stylesheet to it. Maybe you want a QGroupBox? Here is an example:
import sys
import PyQt5.QtWidgets as QtWidgets
def window():
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
w.setWindowTitle('Hello')
w.setGeometry(100,100,200,100)
g = QtWidgets.QGroupBox(w)
layout = QtWidgets.QVBoxLayout()
b = QtWidgets.QPushButton(w)
b.setText("Hello World!")
b1 = QtWidgets.QPushButton(w)
b1.setText("Hello SO!")
layout.addWidget(b)
layout.addWidget(b1)
g.setLayout(layout)
w.setStyleSheet("""
QGroupBox { background-color: rgb(255, 255,255);
} """)
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
window()