Open In App

PyQt5 QSpinBox – Adding background color to the up button when it get pressed

Last Updated : 17 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will see how we can set background color to the up button of the spin box when it get pressed. Spin box is basically have three components one is the line edit other two are up and down button, up button is used to increment the value. Background will appear only when up button is pressed.

In order to do this we have to change the style sheet associated with the spin box, below is the style sheet code

QSpinBox::up-button:pressed
{
background-color : blue;
}

Below is the implementation




# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
  
  
class Window(QMainWindow):
  
    def __init__(self):
        super().__init__()
  
        # setting title
        self.setWindowTitle("Python ")
  
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
  
        # calling method
        self.UiComponents()
  
        # showing all the widgets
        self.show()
  
    # method for widgets
    def UiComponents(self):
        # creating spin box
        self.spin = QSpinBox(self)
  
        # setting geometry to spin box
        self.spin.setGeometry(100, 100, 250, 40)
  
        # setting prefix to spin
        self.spin.setPrefix("Prefix ")
  
        # setting suffix to spin
        self.spin.setSuffix(" Suffix")
  
        # setting style sheet of spin box
        # adding background color to the up-button when it get pressed
        self.spin.setStyleSheet("QSpinBox::up-button:pressed"
                                "{"
                                "background-color : blue;"
                                "}")
  
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())


Output :



Similar Reads

PyQt5 QSpinBox - Adding background color to the down button when it get pressed
In this article we will see how we can set background color to the down button of the spin box when it get pressed. Spin box is basically have three components one is the line edit other two are up and down button, down button is used to decrement the value. This background color will only appear when down button is pressed. In order to do this we
2 min read
PyQt5 QSpinBox - Adding background color when it get pressed
In this article we will see how we can set background color to the spin box when it get pressed, by default the spin box is of white color although the button are of grey color but we can change the color. This background color will appear only when any of the up and down button get pressed. In order to do this we have to change the style sheet ass
2 min read
PyQt5 QSpinBox - Adding background color to the up arrow when pressed
In this article we will see how we can set background color to the up arrow of the spin box when it get pressed. Spin box is basically have three components one is the line edit other two are up and down button. Up arrow is the inner part of the up button, this background color will only appear when up arrow gets pressed. In order to do this we hav
2 min read
PyQt5 – Setting background color to pressed indicator when pressed
In this article we will see how to set background color to the pressed indicator when we press it in the checked state. Its color should get change when it is pressed and goes back to the default state for unchecked state. In order to do this we have to change the style sheet code of the indicator pressed state when it is in checked state, which is
2 min read
PyQt5 QSpinBox - Adding background color to the up button
In this article we will see how we can set background color to the up button of the spin box. Spin box is basically have three components one is the line edit other two are up and down button, up button is used to increment the value. Below is the representation of how background color to the up button looks like. In order to do this we have to cha
2 min read
PyQt5 QSpinBox - Adding background color to the up button when mouse hover over it
In this article we will see how we can set background color to the up button of the spin box when mouse hover over it. Spin box is basically have three components one is the line edit other two are up and down button, up button is used to increment the value. Background will appear only when cursor is on it In order to do this we have to change the
2 min read
PyQt5 QSpinBox - Adding background color to the down button
In this article we will see how we can set background color to the down button of the spin box. Spin box is basically have three components one is the line edit other two are up and down button, down button is used to decrement the value. Below is the representation of how background color to the down button looks like. In order to do this we have
2 min read
PyQt5 QSpinBox - Adding background color to the down button when mouse hover over it
In this article we will see how we can set background color to the down button of the spin box when mouse is hovering over it. Spin box is basically have three components one is the line edit other two are up and down button, down button is used to decrement the value. This background color will only appear when cursor is on the down button of spin
2 min read
PyQt5 - Setting background color to the indicator of radio button when it get pressed
In this article we will see how we can set background color to an indicator of radio button when it get pressed, by default a bluish color is associated when we press the radio button although we can change this color. In order to change the background color of indicator when it get pressed we have to change the style sheet code of radio button, be
2 min read
PyQt5 QSpinBox - Adding border to the up button when pressed
In this article we will see how we can add border to the up button of spin box when it get pressed. Spinbox consist of two buttons up and down, up button is used to increment the value, it has its own default border although we can change it. Customized border will appear to the up button get pressed. In order to do this we have to change the style
2 min read