PyQt5 – 复选框的isRightToLeft()方法
当我们创建一个复选框时,默认的指示器在左手边,我们称之为从左到右的方向,尽管我们可以使用setLayoutDirection方法来改变它的方向。 isRightToLeft方法用于检查布局方向是否从右到左,如果是默认的布局方向,它返回False。
语法: checkbox.isRightToLeft()
参数: 它不需要参数。
返回: 如果布局方向是从右到左,则返回true,否则返回false。
以下是实现方法
# 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)
# checking direction
check = checkbox.isRightToLeft()
# printing the check
print("Before changing direction : " + str(check))
# changing position of indicator
checkbox.setLayoutDirection(Qt.RightToLeft)
# checking direction
check = checkbox.isRightToLeft()
# printing the check
print("After changing direction : " + str(check))
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出:
Before changing direction : False
After changing direction : True