PyQt5 - Setting skin to indicator of radio button

PyQt5 - Setting skin to indicator of radio button

In PyQt5, if you want to change the appearance (or "skin") of the indicator of a radio button (QRadioButton), you would typically use the setStyleSheet() method. This allows you to customize the appearance using a CSS-like syntax.

Below is an example of how you can set a custom skin to the indicator of a QRadioButton:

import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QRadioButton, QVBoxLayout, QWidget class App(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(100, 100, 300, 200) layout = QVBoxLayout() # Create a radio button radio = QRadioButton("Custom Radio Button", self) # Set custom styles to the radio button's indicator radio.setStyleSheet(""" QRadioButton::indicator { width: 20px; height: 20px; border: 2px solid green; border-radius: 10px; } QRadioButton::indicator:checked { background-color: green; } """) layout.addWidget(radio) central_widget = QWidget(self) central_widget.setLayout(layout) self.setCentralWidget(central_widget) if __name__ == "__main__": app = QApplication(sys.argv) window = App() window.show() sys.exit(app.exec_()) 

In the code above, the QRadioButton has been styled such that its indicator:

  1. Is larger than usual (20x20 pixels).
  2. Has a green border.
  3. Fills with a green color when checked.

This is just a basic example. The setStyleSheet() method is quite versatile and allows for extensive customization of widget appearance. Adjust the styles to fit your desired look and feel!


More Tags

create-guten-block exit keychain haversine mpmovieplayercontroller django-queryset mobile-website docker-desktop storyboard contact-form-7

More Programming Guides

Other Guides

More Programming Examples