Open In App

PyQt5 – Background color to checked indicator of Radio Button when pressed

Last Updated : 22 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will see how we can set background color to the indicator of radio button which is in checked state and get pressed. By default a bluish color is associated to the indicator for this although we can change this color.

In order to add background color to the indicator radio button when it is in checked state and get pressed we have to change the style sheet code. Below is the style sheet code.

QRadiobutton::indicator:checked:pressed
{
background-color : lightgreen;
}

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 a radio button
        self.radio_button = QRadioButton(self)
  
        # setting geometry of radio button
        self.radio_button.setGeometry(200, 150, 120, 40)
  
        # setting text to radio button
        self.radio_button.setText("Radio Button")
  
        # changing style sheet code of radio button
        # setting background color to checked indicator when it get pressed
        self.radio_button.setStyleSheet("QRadioButton::indicator:checked:pressed"
                                        "{"
                                        "background-color : lightgreen;"
                                        "}")
  
  
# 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 – Background image to pressed indicator when pressed from checked state | Check Box
In this article we will see how to add background image to the pressed indicator which was initially in the checked state. In order to do this we have to change the style sheet code associated with the check box object and have to add background image to the indicator of checked state when it get pressed. Below is the style sheet code. QCheckBox::i
2 min read
PyQt5 - Background color to checked indicator of Radio Button
In this article we will see how we can see background color to the indicator of radio button when it is in the checked state. By default a blacked circle is associated with the checked state although we can change it with background color. In order to add background color to the indicator for the checked state we have to change the style sheet of t
2 min read
PyQt5 - Background color of checked indicator of radio button when mouse hover
In this article we will see how we can set background color to an indicator of radio button when it is in checked state and mouse hover over it. By default there is no color associated with the indicator. In order to add background color to the indicator when it is in checked state and mouse hover over it we have to change the style sheet code of t
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 - Background color to unchecked indicator of Radio button when pressed
In this article we will see how we can set background color to the indicator of radio button which is in unchecked state and get pressed. By default a bluish color is associated to the indicator for this although we can change this color. In order to add background color to the indicator radio button when it is in unchecked state and get pressed we
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 – Background image to indicator of checked radio button when mouse hover
In this article we will see how we can set background image to the indicator of radio button when mouse hover over it and it was in checked state, by default no image is associated with it although we can add image to it. The background image only appear to the indicator when it was in checked state and when mouse hover over the radio button. In or
2 min read
PyQt5 - Background image of checked Radio button indicator
In this article we will see how we can set background image to an indicator of radio button who is in currently checked state. By default a black circle is associated to the checked state although we can change it with background image. In order to add background image to checked indicator of radio button we have to change the style sheet of radio
2 min read
PyQt5 – Background image of pressed Radio button for checked state
In this article we will see how we can set the background image of pressed radio button when it is in checked state, by default there is no image set to any state or when radio button get pressed. In order to set background image to pressed radio button for checked state we have to change the style sheet for the checked state and when radio button
2 min read
PyQt5 - Set background image to Radio button indicator when pressed
In this article we will see how to set background image to the indicator of radio button when it get pressed. By default when we pressed the radio button there is bluish color associated with it although we can change it. The background image only appear to the indicator when we pressed the radio button. In order to add background image to indicato
2 min read
Article Tags :
Practice Tags :