PyQt5 QCalendarWidget – 获取垂直标题格式
在本文中,我们将了解如何获得 QCalendarWidget 的垂直标题格式。垂直标题是 QCalendarWidget 的一部分,它告诉 ISO 周数,下面是垂直标题的外观表示。
垂直标头基本上有两种可用的格式,一种是 ISOWeekNumbers,它的值为 1,默认为 1 秒为 NoVerticalHeader,其值为 0,它不显示垂直标头。我们使用 setVerticalHeaderFormat 方法来设置垂直标题格式。
In order to do this we will use verticalHeaderFormat method with the QCalendarWidget object.
Syntax : calendar.verticalHeaderFormat()
Argument : It takes no argument
Return : It returns Vertical header format object but when printed it displays the value associated with it.
下面是实现
Python3
# 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 components
def UiComponents(self):
# creating a QCalendarWidget object
calendar = QCalendarWidget(self)
# setting geometry to the calendar
calendar.setGeometry(10, 10, 400, 250)
# setting vertical header format
calendar.setVerticalHeaderFormat(QCalendarWidget.NoVerticalHeader)
# creating a label
label = QLabel(self)
# setting geometry to the label
label.setGeometry(100, 280, 250, 60)
# making label multi line
label.setWordWrap(True)
# getting vertical header format value
value = calendar.verticalHeaderFormat()
# setting text to the label
label.setText("Vertical header format : " + str(value))
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出 :