2024-06-16 09:52:40 发布
网友
我想在QDateTimeEdit()中添加一个默认日期,从现在开始+7天。在
我找到了我做不到的函数setDateTime
dateTimeBegin.setDateTime(datetime.now+7)
或者类似的事情
希望你能帮助我。在
感谢您的预付款
尝试:
import sys from PyQt5.QtCore import * from PyQt5.QtWidgets import * class MyWin(QWidget): def __init__(self): super().__init__() lblCurrentDateTime = QLabel() self.lblDateTimeEdit = QLabel() btn = QPushButton("DateTime + 7 days") btn.clicked.connect(self.editDateDay) lblCurrentDateTime.setText(QDateTime.currentDateTime().toString('yyyy MM dd hh:mm:ss')) self.dateTimeBegin = QDateTimeEdit() self.dt = self.dateTimeBegin.dateTime().currentDateTime() lay = QVBoxLayout(self) lay.addWidget(lblCurrentDateTime) lay.addWidget(self.lblDateTimeEdit) lay.addWidget(btn) def editDateDay(self): self.dateTimeBegin.setDateTime(self.dt.addDays(7)) self.dt = self.dt.addDays(7) currentTime = self.dateTimeBegin.dateTime().toString('yyyy MM dd hh:mm:ss') self.lblDateTimeEdit.setText(self.dateTimeBegin.dateTime().toString('yyyy MM dd hh:mm:ss')) if __name__ =="__main__": qapp = QApplication(sys.argv) w = MyWin() w.show() sys.exit(qapp.exec())
尝试以下操作:
currentTime = QDateTime.currentDateTime() dateTimeBegin.setDateTime(currentTime.addDays(7))
尝试:
尝试以下操作:
相关问题 更多 >
编程相关推荐