In this article we will see how to change the border of the radio button. By default indicator is round and has a black border although we can change the size and the color of the border.
In order to change the border of the indicator we have to change the style sheet of the indicator associated with the radio button. Below is the style sheet code.
QRadioButton::indicator
{
border : 2px solid green;
}
Note : When we alter style sheet of indicator it shapes changes to square from circle.
Below is the implementation.
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__()
self .setWindowTitle( "Python " )
self .setGeometry( 100 , 100 , 600 , 400 )
self .UiComponents()
self .show()
def UiComponents( self ):
radio_button = QRadioButton( self )
radio_button.setGeometry( 200 , 150 , 120 , 40 )
radio_button.setText( "Radio Button" )
radio_button.setStyleSheet( "QRadioButton::indicator"
"{"
"border : 2px solid green"
"}" )
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
