PyQt5 – 右侧带有指示器的复选框
在本文中,我们将看到如何将指标设置在复选框的右侧。复选框基本上有两个组件,第一个是指标,另一个是标签,默认指标在左侧。为了使指示器位于右侧,我们必须将其布局方向从左侧更改为右侧。
为此,我们将使用setLayoutDirection
方法。
Syntax : checkbox.setLayoutDirection(Qt.RightToLeft)
Argument : It takes Qt object as argument.
Action performed : It will change the layout of check box.
下面是实现。
# 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 the check-box
checkbox = QCheckBox('Geek ?', self)
# setting geometry of check box
checkbox.setGeometry(200, 150, 100, 30)
# changing position of indicator
checkbox.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())
输出 :