PyQt5 QCalendarWidget - 设置垂直标题格式
在本文中,我们将了解如何设置 QCalendarWidget 的垂直标题格式。垂直标题是 QCalendarWidget 的一部分,它告诉 ISO 周数,下面是垂直标题的外观表示。
垂直标头基本上有两种可用的格式,一种是 ISOWeekNumbers,它的值为 1,默认为 NoVerticalHeader,它的值为 0,它不显示垂直标头。
In order to do this we will use setVerticalHeaderFormat method with the QCalendarWidget object.
Syntax : calendar.setVerticalHeaderFormat(format)
Argument : It takes vertical header format as argument
Return : It returns None
下面是实现
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)
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出 :