PyQt5 – orientation() 方法 进度条
当我们在PyQt5中创建进度条时,它的方向默认是水平的,但我们可以在setOrientation方法的帮助下改变它。为了获得关于进度条方向的信息,即它是水平的还是垂直的,我们可以使用这个方法。
语法: bar.orientation()
参数: 它不需要参数。
返回: 它将返回Orientation对象,尽管当我们打印它时,它将打印1表示水平方向,2表示垂直方向。
下面是实现方法。
# 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 progress bar
bar = QProgressBar(self)
# setting geometry to progress bar
bar.setGeometry(250, 90, 30, 200)
# set value to progress bar
bar.setValue(40)
# setting alignment to center
bar.setAlignment(Qt.AlignCenter)
# setting orientation to vertical
bar.setOrientation(QtCore.Qt.Vertical)
# getting orientation
orientation = bar.orientation()
# printing its type
print(type(orientation))
# printing the orientation
print(orientation)
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出:
class 'PyQt5.QtCore.Qt.Orientation'
2