PyQt5 - 右侧的单选按钮指示器
在本文中,我们将看到如何在右侧制作单选按钮的指示器。默认情况下,当我们创建单选按钮时,其指示器位于左侧。单选按钮的指示器是圆形的可检查部分,表示它是否被选中。
下面是普通单选按钮与指示器在右侧的单选按钮。
In order to make this type of widget we have to do the following –
1. Create a radio button using QRadioButton class.
2. Change its layout direction with the help of setLayoutDirection
by default it is left to right, set it to right to left.
下面是实现。
# 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
radio_button = QRadioButton("Radio Button", self)
# setting geometry of radio button
radio_button.setGeometry(200, 150, 100, 40)
# setting layout direction of radio button
radio_button.setLayoutDirection(Qt.RightToLeft)
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出 :