PyQt5 QCalendarWidget – 访问 Base Size 值
在本文中,我们将了解如何访问 QCalendarWidget 的基本大小值。默认情况下,基本尺寸的宽度和高度都为零,如果日历定义了 sizeIncrement,基本尺寸用于计算适当的日历尺寸,即当窗口尺寸改变时它的尺寸改变。基本大小是日历的初始大小。基本大小可以在 setBaseSize 方法的帮助下设置到日历中。
In order to do this we will use baseSize method with the QCalendarWidget object.
Syntax : calendar.baseSize()
Argument : It takes no argument
Return : It return QSize object
下面是实现:
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
self.calendar = QCalendarWidget(self)
# setting geometry to the calendar
self.calendar.setGeometry(50, 10, 400, 250)
# setting base size
self.calendar.setBaseSize(400, 25)
# creating a label
label = QLabel(self)
# setting geometry
label.setGeometry(120, 280, 200, 60)
# making it multi line
label.setWordWrap(True)
# getting the base size
value = self.calendar.baseSize()
# setting text to the label
label.setText("Base Size : " + str(value))
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出 :