📜  PyQt5 QCalendarWidget – 使尺寸完美契合

📅  最后修改于: 2022-05-13 01:54:48.976000             🧑  作者: Mango

PyQt5 QCalendarWidget – 使尺寸完美契合

在本文中,我们将了解如何根据外观使 QCalendarWidget 尺寸完美契合,即尺寸不应该更大或不应该更小。日历是一个很大的小部件,因此有时设计师会错误地将尺寸缩小,只有日历的一部分可见。它可以通过手动改变大小来调整,但命中和试行方法需要时间,也不准确。

下面是实现

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(450, 50, 100, 100)
 
        # creating another calendar
        geek_calendar = QCalendarWidget(self)
 
        # adjusting the size of geek calendar
        geek_calendar.adjustSize()
 
 
# create pyqt5 app
App = QApplication(sys.argv)
 
# create the instance of our Window
window = Window()
 
 
# start the app
sys.exit(App.exec())


输出 :