我有 2 个 QCalendarWidget 对象,我需要将第一个对象的选定日期设置为第二个日历中的最小日期。我的日历代码看起来像这样
class Calendar(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.VBox = QtWidgets.QVBoxLayout()
self.cal = QtWidgets.QCalendarWidget(self)
self.cal.setGridVisible(True)
self.VBox.addWidget(self.cal)
self.setLayout(self.VBox)
在其他类中,我创建了 2 个对象类型 Calendar
self.date1 = Calendar()
self.date2 = Calendar()
我试图像这样为 self.date2 设置最小日期
self.date2.cal.setMinimumDate(self.date1.cal.selectedDate())
但它不起作用。它将当前日期设置为最小日期,而不是从第一个日历中选择日期。我知道它为什么会发生——因为 selectedDate() 在无法获取其他内容时自动设置当前日期。但是回到我的标题问题,如何设置从第一个日历中选择日期作为第二个日历的最小值?