Search code examples
pyside2

PySide, editing spinbox colors


How in PySide would you edit the background color of the field of a spinbox, using stylesheets, but not change the color of the up-button and the down-buttons? Is there a flag to only adjust the "field?"

self.intensity_multiplier_spinbox_list[iter].setStyleSheet("QDoubleSpinBox {background-color: orange;color: black};")

Solution

  • You can use QPalette:

    import sys
    from PySide2 import QtGui, QtWidgets
    
    
    if __name__ == "__main__": 
        app = QtWidgets.QApplication(sys.argv)
        w = QtWidgets.QDoubleSpinBox()
        pal = w.palette()
        pal.setColor(QtGui.QPalette.Base, QtGui.QColor("orange"))
        w.setPalette(pal)
        w.show()
        sys.exit(app.exec_())
    

    enter image description here